#include #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)); #define chmax(x,y) x = max((x),(y)); using namespace std; using ll = long long ; using P = pair ; using pll = pair; const int INF = 1e9; const long long LINF = 1e17; const int MOD = 1000000007; //const int MOD = 998244353; const double PI = 3.14159265358979323846; int a[20][20]; int main(){ int n,m; cin >> n >> m; rep(i,n)rep(j,n) cin >> a[i][j]; ll ans = LINF; rep(mask,4){ ll res = 0; int t = 0; vector> maze(n,vector(n,0)); if(mask&1){ ++t; rep(i,n){ maze[i][i] = 1; res += a[i][i]; } } if(mask>>1&1){ ++t; rep(i,n){ maze[i][n-i-1] = 1; res += a[i][n-i-1]; } } for(int bit=0;bit<(1<>i&1){ rep(j,n){ if(maze[i][j]==0) ret += a[i][j]; } } } int num = m - pop; vector b(n,0); rep(i,n){ rep(j,n){ if(bit>>j&1) continue; if(maze[j][i]==1) continue; b[i] += a[j][i]; } } sort(b.begin(),b.end()); rep(i,num) ret += b[i]; chmin(ans,res+ret); } } cout << ans << endl; return 0; }