#include<bits/stdc++.h>
using namespace std;
// my choco pie
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define PII pair<int,int>
#define all(x) x.begin(),x.end()
#define VI vector<int>
#define VII vector<pair<int,int> >
#define VL vector<long long int >
#define VLL vector<pair<long long ,long long > >
#define PLL pair<long long ,long long >
#define itr iterator
#define fill(x,v) fill(all(x),v)
// my fastest car series
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)
#define ms(x) memset(x,0,sizeof(x))
// data pies
#define ll long long int
#define li long int
#define ff float
#define db double
// loopi loops
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>=b;i--)
// debugger
#define print_v(x) for(int i=0;i<x.size();i++) cout << x[i] << " "
#define debug(x) cout << "#debug" << " " << x << endl
#define MOD 1000000007
int random_long(int digit=8)
{
int len=digit;
int x=0;
for ( int i = 0; i < len; ++i )
{
int dig = rand() % 10;
while ( x == 0 && dig == 0 )
dig = rand() % 10;
x = x * 10 + dig;
}
return x;
}
int random(int l, int r)
{
int diff = r - l + 1;
return l+random_long()%diff;
}
#define inf INT_MAX/5
int main(){
int n,k;
cin >> n >> k;
int P[k+1][n+1],i,j,DP[n+5][1<<k];
ms(P),ms(DP);
rep(i,1,k+1)
rep(j,1,n+1)
cin >> P[i][j];
int sz=1<<k,l,m;
rep(i,1,n+1)
rep(j,0,sz)
DP[i][j]=inf;
int ans=inf;
repr(i,n,1){
rep(j,0,sz){
rep(l,0,k){
if(!(j&(1<<l))){
int val2=0;
rep(m,i,n+1){
val2+=P[l+1][m];
DP[i][j]=min(DP[i][j],val2+DP[m+1][j|(1<<l)]);
}
}
}
}
}
cout << DP[1][0] << endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIG15IGNob2NvIHBpZQoKI2RlZmluZSBmdCBmaXJzdAojZGVmaW5l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