#include <bits/stdc++.h>
using namespace std;
const int maxn = 88;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 0;
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n, k, w[maxn][maxn], ans = 1e9, seq[maxn], cnt[maxn];
pair<int, int> www[maxn][maxn][4];
int calc() {
  int s = 0;
  for (int i = (1); i <= (k / 2); i++)
    for (int j = (0); j <= (3); j++) {
      if (!www[seq[i]][seq[i - 1]][j].second) return 1e9;
      if (!cnt[www[seq[i]][seq[i - 1]][j].second]) {
        s += www[seq[i]][seq[i - 1]][j].first;
        break;
      }
    }
  return s;
}
void dfs(int dep) {
  if (dep >= k / 2) return void(ans = min(ans, calc()));
  for (int i = (1); i <= (n); i++) {
    cnt[i]++;
    seq[dep] = i;
    dfs(dep + 1);
    cnt[i]--;
  }
}
int main() {
  n = read();
  k = read();
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++) w[i][j] = read();
  for (int i = (1); i <= (n); i++) w[i][i] = 1e9;
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++) {
      for (int k = (0); k <= (3); k++) www[i][j][k] = make_pair(1e9, 0);
      for (int k = (1); k <= (n); k++) {
        for (int x = (0); x <= (3); x++)
          if (w[i][k] + w[k][j] < www[i][j][x].first) {
            for (int y = (3); y >= (x + 1); y--)
              www[i][j][y] = www[i][j][y - 1];
            www[i][j][x] = make_pair(w[i][k] + w[k][j], k);
            break;
          }
      }
    }
  seq[0] = seq[k / 2] = 1;
  cnt[1] = 1;
  dfs(1);
  printf("%d\n", ans);
}
