#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MAXN = (int)85 + 5;
long long n;
long long grid[MAXN][MAXN];
long long dp[MAXN][15];
bool a[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int k;
  cin >> n >> k;
  long long ans = INF;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> grid[i][j];
      if (i == j) grid[i][j] = mod;
    }
  }
  srand(time(NULL));
  for (int i = 1; i <= 12000; i++) {
    memset(dp, 0x7f, sizeof(dp));
    for (int j = 2; j <= n; j++) {
      a[j] = rand() % 2;
    }
    dp[1][0] = 0;
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= n; l++) {
        if (a[l] % 2 != j % 2) {
          continue;
        }
        for (int t = 1; t <= n; t++) {
          dp[l][j] = min(dp[l][j], dp[t][j - 1] + grid[t][l]);
        }
      }
    }
    ans = min(ans, dp[1][k]);
  }
  cout << ans << '\n';
}
