#include <bits/stdc++.h>
using namespace std;
const int maxn = 85;
int n, k, d[maxn][maxn];
int col[maxn];
long long dp[maxn][maxn];
signed main() {
  srand(time(0));
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &d[i][j]);
  int ti = 1 << k + 2;
  long long ans = 4e18;
  while (ti--) {
    for (int i = 1; i <= n; i++) col[i] = rand() % 2;
    memset(dp, 127, sizeof(dp));
    dp[1][0] = 0;
    for (register int i = 1; i <= k; ++i) {
      for (register int j = 1; j <= n; ++j) {
        for (register int x = 1; x <= n; ++x) {
          if (col[j] == col[x]) continue;
          dp[x][i] = min(dp[x][i], dp[j][i - 1] + d[j][x]);
        }
      }
    }
    ans = min(ans, dp[1][k]);
  }
  printf("%lld\n", ans);
}
