#include <bits/stdc++.h>
using namespace std;
int n, k, c[82][82], dp[12][82], col[82], i, j, l, r, sol;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      cin >> c[i][j];
    }
  }
  sol = 1000000000;
  for (r = 1; r <= 10000; r++) {
    col[1] = 0;
    for (i = 2; i <= n; i++) col[i] = rand() % 2;
    for (j = 1; j <= n; j++)
      if (col[j] != col[1])
        dp[1][j] = c[1][j];
      else
        dp[1][j] = 1000000000;
    for (i = 2; i <= k; i++) {
      for (j = 1; j <= n; j++) {
        dp[i][j] = 1000000000;
        for (l = 1; l <= n; l++) {
          if (col[l] != col[j] && dp[i - 1][l] != 1000000000) {
            dp[i][j] = min(dp[i][j], dp[i - 1][l] + c[l][j]);
          }
        }
      }
    }
    sol = min(sol, dp[k][1]);
  }
  cout << sol << "\n";
  return 0;
}
