#include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair; const ll INF = (1LL << 61); ll mod = (ll)1e9 + 7; signed main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M; cin >> N >> M; vector>A(N, vector(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> A[i][j]; } } ll ans = INF; for (int i = 0; i < 4; i++) { vector>now(N, vector(N)); ll tmp = 0; ll tmp2 = 0; for (int j = 0; j < 2; j++) { if (i & (1 << j)) { if (j == 0) { for (int k = 0; k < N; k++) { if (!now[k][k]) { now[k][k] = true; tmp += A[k][k]; } } tmp2++; } else { for (int k = 0; k < N; k++) { if (!now[k][N - k - 1]) { now[k][N - k - 1] = true; tmp += A[k][N - k - 1]; } } tmp2++; } } } for (int bit = 0; bit < (1 << N); bit++) { vector>b = now; ll a = tmp; ll cnt = tmp2; for (int j = 0; j < N; j++) { if (bit & (1 << j)) { for (int k = 0; k < N; k++) { if (!now[j][k]) { now[j][k] = true; tmp += A[j][k]; } } cnt++; } } ll need = M - cnt; if (need <= 0) { ans = min(ans, tmp); tmp = a; now = b; continue; } if (need > N)continue; vectors(N); for (int k = 0; k < N; k++) { for (int j = 0; j < N; j++) { if (!now[j][k]) { s[k] += A[j][k]; } } } sort(s.begin(), s.end()); for (int j = 0; j < need; j++) { tmp += s[j]; } ans = min(ans, tmp); tmp = a; now = b; } } cout << ans << endl; return 0; }