#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[80][80];
int clr[80];
long long dp[11][80];
const long long INF = 1e18;
void solve() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  long long ans = INF;
  for (int iter = 0; iter < 512 * 10; iter++) {
    for (int v = 1; v < n; v++) {
      clr[v] = (rng() & 1);
    }
    fill(dp[0], dp[0] + n, INF);
    dp[0][0] = 0;
    for (int d = 1; d <= k; d++) {
      fill(dp[d], dp[d] + n, INF);
      for (int v = 0; v < n; v++) {
        for (int u = 0; u < n; u++) {
          if (clr[v] == clr[u]) continue;
          dp[d][u] = min(dp[d][u], dp[d - 1][v] + a[v][u]);
        }
      }
    }
    ans = min(ans, dp[k][0]);
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  solve();
}
