#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
    lli n,m;
    cin>>n;
    cin>>m;
    lli a[n+5][m+5];
    lli minimum = INT_MAX;

    fff(i,1,n){
        fff(j,1,m){
            cin>>a[i][j];
        }
    }
    if(n==2){
        lli pref[m+5];
        lli koraci[m+5];
        pref[0] = 0;
        koraci[0] = 0;
        lli suf[m+5];
        suf[m] = 0;
        fff(i,1,m){
            pref[i] = a[2][i] + pref[i-1];
            koraci[i] = koraci[i-1] + pref[i];
            suf[m-i] = suf[m+1-i] + a[1][m-i];
        }

        ff(i,0,m){
            if(minimum>(koraci[i] + suf[i+1])){
                minimum = koraci[i] + suf[i+1];
            }
        }
        cout<<minimum<<endl;
        /*lli res = pref[m]+suf[1]-maximum;
        cout<<res<<endl;*/
    }
    return 0;
}