#include <iostream>
#define MAXN 1000010
#define ll long long
using namespace std;
ll a[MAXN], b[MAXN];
ll sum;
int main()
{
    ll n, m; cin >> n >> m;
    for (ll i=0; i<n; i++)
    {
        for (ll j=0; j<m; j++)
        {
            ll x; cin >> x;
            sum+=x;
            if (i==0) a[j+1]=a[j]+x;
            if (i==1) b[j+1]=b[j]+x;
        }
    }

    if (n==2)
    {
        ll res=INT_MIN, I, J;
        for (ll i=1; i<=n; i++)
        {
            for (ll j=1; j<=m; j++)
            {
                ll ans=a[j]+(b[m]-b[j-1]);
                if (ans>res)
                {
                    res=ans;
                    I=i; J=j;
                }
            }
        }
        ll ans=0;
        ans=a[m]-a[J];
        for (ll i=1; i<J; i++) ans+=(b[i]-b[i-1])*(J-i);
        cout << ans << endl;
    }
    return 0;
}