#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int mp[85][85], c[85], dp[85], tmp[85], ans;
int main() {
  srand(int(time(NULL)));
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &mp[i][j]);
  ans = inf;
  for (int i = 0; i < 10000; i++) {
    for (int j = 1; j <= n; j++) c[j] = rand() % 2;
    for (int j = 1; j <= n; j++) dp[j] = inf;
    for (int j = 1; j <= n; j++)
      if (c[j] != c[1]) dp[j] = mp[1][j];
    for (int j = 1; j <= n; j++) tmp[j] = inf;
    for (int j = 2; j <= k; j++) {
      for (int kk = 1; kk <= n; kk++)
        for (int l = 1; l <= n; l++)
          if (c[kk] != c[l]) tmp[l] = min(tmp[l], dp[kk] + mp[kk][l]);
      for (int kk = 1; kk <= n; kk++) dp[kk] = tmp[kk];
      for (int kk = 1; kk <= n; kk++) tmp[kk] = inf;
    }
    ans = min(ans, dp[1]);
  }
  printf("%d\n", ans);
  return 0;
}
