#include #include #include #include #include #include #include using namespace std; #define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++) #define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--) using ll = long long; const ll mod = 998244353; const ll inf = 1000000000; int main(){ ll N,M; scanf("%lld%lld",&N,&M); vector> A(N , vector(N)); ll ans = inf; rep(i,0,N){ rep(j,0,N){ scanf("%lld",&A[i][j]); } } rep(i,0,1<<(N+2)){ vector> B(N , vector(N)); rep(x,0,N){ rep(y,0,N){ B[x][y] = A[x][y]; } } ll rem = M; ll tmp = 0; rep(y,0,N){ if (((1< 0){ rem -= 1; rep(x,0,N){ tmp += B[x][y]; B[x][y] = 0; } } } ll yy = N; if (((1< 0){ rem -= 1; rep(k,0,N){ tmp += B[k][k]; B[k][k] = 0; } } yy = N+1; if (((1< 0){ rem -= 1; rep(k,0,N){ tmp += B[k][N-k-1]; B[k][N-k-1] = 0; } } //cout << rem << " " << tmp << endl; if (rem <= 0) ans = min(ans,tmp); else{ vector lis(N,0); rep(x,0,N){ rep(y,0,N){ lis[x] += B[x][y]; } } sort(lis.begin(),lis.end()); rep(c,0,rem) tmp += lis[c]; ans = min(ans , tmp); } } cout << ans << endl; }