#include <bits/stdc++.h>
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n,m;
    cin >> n >> m;
    long long matrica[n][m];
    long long s1 = 0,s2 =0;
    long long prefs1[m],prefs2[m];
    for ( int i = 0 ; i < n ; i++)
        for ( int j = 0 ; j < m ; j++)
        {
            cin >> matrica[i][j];
            if ( i == 0)
            {
                s1 += matrica[i][j];
                prefs1[j] = s1;
            }
            if ( i == 1)
            {
                s2 += matrica[i][j];
                prefs2[j] = s1;
            }
        }
    long long izlaz = 10e10;
    if ( n == 2)
    {
        for ( int i = 0 ; i < m ; i++)
        {
            long long s = s1 + s2 - (prefs1[i-1] + prefs2[m-i-1] - prefs2[i]);
            izlaz = min(izlaz,s);
        }
        cout << izlaz;
    }

}