#include <bits/stdc++.h>
using namespace std;
long long n, K, a[105][105], f[105][105], col[105], ans = 9e18;
signed main() {
  srand(time(0));
  scanf("%lld %lld", &n, &K);
  for (register long long i = 1; i <= n; i++) {
    for (register long long j = 1; j <= n; j++) scanf("%lld", &a[i][j]);
  }
  register long long Time = 5000;
  while (Time--) {
    memset(f, 60, sizeof(f));
    for (register long long i = 1; i <= n; i++) col[i] = rand() % 2;
    f[0][1] = 0;
    for (register long long k = 1; k <= K; k++) {
      for (register long long i = 1; i <= n; i++) {
        for (register long long j = 1; j <= n; j++)
          if (col[i] ^ col[j]) f[k][j] = min(f[k][j], f[k - 1][i] + a[i][j]);
      }
    }
    ans = min(ans, f[K][1]);
  }
  printf("%lld\n", ans);
  return 0;
}
