#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define FAST ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);

#define ff(i,a,b) for(int (i) = (a);(i)<(b);(i)++)
#define fff(i,a,b) for(int (i) = (a);(i)<=(b);(i)++)
#define bff(i,a,b) for(int (i) = (a);(i)>(b);(i)++)
#define bfff(i,a,b) for(int (i) = (a);(i)>=(b);(i)++)

#define pb push_back
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long int lli;


int main()
{
    FAST
    int n,m;
    cin>>n;
    cin>>m;
    int a[n+5][m+5];
    int minimum = INT_MAX;

    fff(i,1,n){
        fff(j,1,m){
            cin>>a[i][j];
        }
    }
    if(n==2){
        lli pref[m+5];
        pref[0] = 0;
        lli suf[m+5];
        suf[m+1] = 0;
        lli maximum = 0;
        lli sum= 0;
        fff(i,1,m){
            sum+= a[1][i] + a[2][i];
            pref[i] = a[1][i] + pref[i-1];
            suf[m+1-i] = suf[m+2-i] + a[2][m+1-i];
        }
        fff(i,1,m){
            if((pref[i]+suf[i])>maximum){
                maximum = pref[i]+suf[i];
            }
        }
        lli res = sum-maximum;
        cout<<res<<endl;
    }
    return 0;
}