#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define cy cout << "YES" << endl;
#define cn cout << "NO" << endl;
#define pf push_front
#define pb push_back
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) cout << x << endl;
#define prints(x) cout << x << ' ';


void solve()
{
    int mx[2][100000];

    int n,m; cin >> n >> m;

    ll sum = 0;


    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
        {
            cin >> mx[i][j];
            sum+=mx[i][j];
        }
 
    if(n == 2)
    {
        vi prefPrvi(m);
        vi prefDrugi(m);

        prefPrvi[0] = 0;
        prefDrugi[0] = mx[1][0];

        for(int i = 1; i < m; i++)
        {
            prefPrvi[i] = prefPrvi[i-1] + mx[0][i];
            prefDrugi[i] = prefDrugi[i-1] + mx[1][i];
        }

        prefDrugi[m-1] = prefDrugi[m-2];

        int ans = 0 ;

        for(int i = 0; i < m; i++)
        {
            ans = max(ans, prefPrvi[i] + (prefDrugi[m-1] - prefDrugi[i]) +  mx[0][0] + mx[1][m]);
        }

        cout << ans << endl;
    }


}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int tt= 1;
    while(tt--)
    {
        solve();
    }
}