#include <bits/stdc++.h>
using namespace std;
const int N = 80;
const int K = 11;
const int INF = 1e9;
int n, k;
int g[N][N];
int color[N];
int dist[K][N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  mt19937 rnd(239);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> g[i][j];
    }
  }
  int ans = INF;
  for (int it = 0; it < 1e4; ++it) {
    for (int v = 0; v < n; ++v) {
      color[v] = rnd() & 1;
    }
    fill(dist[0] + 1, dist[0] + n, INF);
    for (int i = 1; i <= k; ++i) {
      fill(dist[i], dist[i] + n, INF);
      for (int v = 0; v < n; ++v) {
        for (int u = 0; u < n; ++u) {
          if (color[v] != color[u]) {
            dist[i][u] = min(dist[i][u], dist[i - 1][v] + g[v][u]);
          }
        }
      }
    }
    ans = min(ans, dist[k][0]);
  }
  cout << ans << '\n';
  return 0;
}
