#include <bits/stdc++.h>
using namespace std;
const long long N = 83, K = 11, INF = 1e12;
long long adj[N][N], col[N], dp[N][K];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  srand(time(0));
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++) cin >> adj[i][j];
  for (long long i = 0; i < n; i++) adj[i][i] = INF;
  long long ans = INF, t = 3000;
  while (t--) {
    for (long long i = 0; i < n; i++) col[i] = rand() % 2;
    for (long long i = 0; i < n; i++)
      for (long long c = 0; c <= k; c++) dp[i][c] = INF;
    dp[0][0] = 0;
    for (long long c = 1; c <= k; c++)
      for (long long i = 0; i < n; i++)
        for (long long s = 0; s < n; s++)
          if (col[i] != col[s])
            dp[s][c] = min(dp[s][c], dp[i][c - 1] + adj[i][s]);
    ans = min(ans, dp[0][k]);
  }
  cout << ans;
  return 0;
}
