#include <bits/stdc++.h>
using namespace std;
const int N = 82;
int n, k, g[N][N], ans = 1e9, a[17];
pair<int, long long> dp[N][N][7];
int solve(int x) {
  int p = 0, o = 0;
  for (int i = 1; i < k / 2; i++) {
    a[i] = x % 80, x /= 80;
    if (a[i] >= n) return 1e9;
  }
  for (int i = 0; i < k / 2; i++) {
    o = 0;
    for (int j = 0; j < 6; j++) {
      if (dp[a[i]][a[i + 1]][j].second != a[0] &&
          dp[a[i]][a[i + 1]][j].second != a[1] &&
          dp[a[i]][a[i + 1]][j].second != a[2] &&
          dp[a[i]][a[i + 1]][j].second != a[3] &&
          dp[a[i]][a[i + 1]][j].second != a[4]) {
        p += dp[a[i]][a[i + 1]][j].first;
        o = 1;
        break;
      }
    }
    if (o == 0) return 1e9;
  }
  return p;
}
int main() {
  for (int i = 0; i < 10; i++) a[i] = 1e9;
  scanf("%d%d", &n, &k);
  a[0] = 0;
  a[k / 2] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) scanf("%d", &g[i][j]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int l = 0; l < 6; l++) dp[i][j][l].first = 1e9;
      for (int l = 1; l < n; l++) {
        if (l != i && l != j) {
          dp[i][j][5] = make_pair(g[i][l] + g[l][j], l);
          sort(dp[i][j], dp[i][j] + 6);
        }
      }
    }
  }
  for (int i = 0; i < 4e7 + 5e6; i++) ans = min(ans, solve(i));
  ;
  cout << ans << endl;
}
