#include <bits/stdc++.h>
#define STEF ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define nl '\n'
int MOD =1000000007;
using namespace std;


int main(){
	STEF;
    ll n,m;
    cin>>n>>m;
    ll a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }

    ll sum1=0;
    for(int i=0;i<n;i++){sum1+=a[0][i];}
    ll sum2=0;
    for(int i=0;i<n;i++){sum2+=a[1][i];}
    cout<<min(sum1,sum2);
	return 0;
}