#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long maxn = (long long)1e6 + 5;
const long long mod = 998244353;
const long long inf = 0x3f3f3f3f;
long long T = 1;
long long f[20][100], dis[100][100];
long long c[100];
void solve() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= n; ++j) cin >> dis[i][j];
  long long ans = LLONG_MAX;
  for (long long cas = 1; cas <= 5000; ++cas) {
    for (long long i = 1; i <= n; ++i) {
      c[i] = rnd() & 1;
      f[0][i] = 1e18;
    }
    f[0][1] = 0;
    for (long long i = 0; i <= k - 1; ++i) {
      for (long long j = 1; j <= n; ++j) f[i + 1][j] = 1e18;
      for (long long j = 1; j <= n; ++j) {
        for (long long u = 1; u <= n; ++u) {
          if (c[j] != c[u]) {
            f[i + 1][u] = min(f[i + 1][u], f[i][j] + dis[j][u]);
          }
        }
      }
    }
    ans = min(ans, f[k][1]);
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  while (T--) solve();
  return 0;
}
