#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define meta int tm = (tl + tr) / 2, x = i * 2 + 1, y = x + 1
const int SN = 21;
const int TN = 4 * SN;
const int oo = 1e18;
const int mod = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int n, k, a[SN][SN], mn = oo, dp[(1 << SN)];
int solve (int mask) {
if (__builtin_popcount(mask) == k) return 0;
if (dp[mask] != oo) return dp[mask];
for (int i = 0; i < n; i++) {
if (!(mask & (1 << i))) continue;
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (!(mask & (1 << j))) continue;
dp[mask] = min(dp[mask], solve((mask ^ (1 << i))) + a[i][j]);
}
}
return dp[mask];
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i = 0; i < (1 << n); i++)
dp[i] = oo;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
cout << solve((1 << n) - 1);
return 0;
}