#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n, k, a[100][100], col[maxn];
long long dp[20][100];
long long solve() {
  for (int i = 1; i <= n; i++) dp[0][i] = inf;
  dp[0][1] = 0;
  for (int kk = 1; kk <= k; kk++) {
    for (int i = 1; i <= n; i++) dp[kk][i] = inf;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (col[i] != col[j])
          dp[kk][j] = min(dp[kk][j], dp[kk - 1][i] + a[i][j]);
      }
    }
  }
  return dp[k][1];
}
mt19937 rnd(time(NULL));
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  }
  long long ans = inf;
  for (int t = 1; t <= 5000; t++) {
    for (int i = 1; i <= n; i++) col[i] = rnd() % 2;
    ans = min(ans, solve());
  }
  printf("%lld\n", ans);
}
