#include <bits/stdc++.h>
using namespace std;
const int N = 81;
int dis[N][N], dp[11][N];
int col[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> dis[i][j];
    }
  }
  mt19937 rd(chrono::system_clock::now().time_since_epoch().count());
  int ans = INT_MAX;
  for (int t = 0; t < (1 << k) * 20; t++) {
    memset(dp, 0x3f, sizeof dp);
    uniform_int_distribution<> rng(0, 1);
    for (int i = 1; i <= n; ++i) col[i] = rng(rd);
    dp[0][1] = 0;
    for (int i = 0; i < k; ++i) {
      for (int j = 1; j <= n; ++j) {
        for (int l = 1; l <= n; ++l) {
          if (col[j] != col[l]) {
            dp[i + 1][l] = min(dp[i + 1][l], dp[i][j] + dis[j][l]);
          }
        }
      }
    }
    ans = min(ans, dp[k][1]);
  }
  cout << ans;
}
