#include <bits/stdc++.h>
using namespace std;
int to[85], K, i, j, k, x, n, ys[85], a[85][85], dp[85][12], ans = 1e9;
int main() {
  srand(time(NULL));
  cin >> n >> K;
  for (i = 1; i <= n; a[i][i] = 1e9, ++i)
    for (j = 1; j <= n; ++j) cin >> a[i][j];
  for (i = 1; i <= 50000; ++i) {
    for (j = 1; j <= n; ++j) ys[j] = rand() & 1;
    memset(dp, 0x3f, sizeof(dp));
    dp[1][0] = 0;
    for (x = 0; x < K; ++x) {
      for (j = 1; j <= n; ++j) {
        if (dp[j][x] <= 1e9) {
          for (k = 1; k <= n; ++k)
            if (ys[k] ^ ys[j])
              dp[k][x + 1] = min(dp[k][x + 1], dp[j][x] + a[j][k]);
        }
      }
    }
    ans = min(ans, dp[1][K]);
  }
  cout << ans;
}
