#include <bits/stdc++.h>
using namespace std;
const int MAXN = 85;
int dp[12][MAXN], dis[MAXN][MAXN], co[MAXN];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &dis[i][j]);
  int cnt = 512 * 20;
  int ans = 1e9 + 5;
  srand(time(0));
  while (cnt--) {
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 1; i <= n; i++) co[i] = rand() % 2;
    dp[0][1] = 0;
    for (int c = 0; c < k; c++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
          if (i == j) continue;
          if (co[i] ^ co[j])
            dp[c + 1][j] = min(dp[c + 1][j], dp[c][i] + dis[i][j]);
        }
    ans = min(ans, dp[k][1]);
  }
  cout << ans << endl;
  return 0;
}
