#include <bits/stdc++.h>
using namespace std;
int main() {
  srand(time(0));
  int n, k;
  cin >> n >> k;
  vector<vector<int>> arr(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> arr[i][j];
    }
  }
  int res = 2e9;
  for (int x = 0; x < 10000; ++x) {
    vector<int> color(n);
    for (int i = 0; i < n; ++i) {
      color[i] = rand() % 2;
    }
    vector<vector<int>> dp(n, vector<int>(k + 1, 2e9));
    dp[0][0] = 0;
    for (int i = 1; i <= k; ++i) {
      for (int u = 0; u < n; ++u) {
        for (int v = 0; v < n; ++v) {
          if (u == v || color[u] == color[v]) continue;
          dp[v][i] = min(dp[v][i], dp[u][i - 1] + arr[u][v]);
        }
      }
    }
    res = min(res, dp[0][k]);
  }
  cout << res << endl;
}
