#include <bits/stdc++.h>
using namespace std;
const int MAXN = 81;
const int MAXK = 15;
long long dp[MAXN][MAXK];
int cost[MAXN][MAXN];
bool co[MAXN];
int n, k;
int main(void) {
  cin >> n >> k;
  srand(clock() ^ time(0) + rand());
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) cin >> cost[i][j];
  int T = 5000;
  long long ans = 1e18;
  while (T--) {
    for (int i = 1; i <= n; ++i) co[i] = rand() & 1;
    memset(dp, 63, sizeof dp);
    dp[1][0] = 0;
    for (int p = 1; p <= k; ++p)
      for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
          if (co[i] ^ co[j])
            dp[j][p] = min(dp[i][p - 1] + cost[i][j], dp[j][p]);
    ans = min(ans, dp[1][k]);
  }
  cout << ans << '\n';
  return 0;
}
