#include <bits/stdc++.h>
const int N = 85;
using namespace std;
int n, k;
int a[N];
pair<long long, int> F[N][N][10];
long long c[N][N], res = 1e15;
int check(int x) {
  for (int i = 0; i < k / 2; i++)
    if (x == a[i]) return 0;
  return 1;
}
long long Calc(int mask) {
  for (int i = 1; i < k / 2; i++) {
    a[i] = mask % 80;
    mask /= 80;
    if (a[i] > n) return 1e15;
  }
  long long Sum = 0;
  for (int i = 0; i < k / 2; i++) {
    int cc = 0;
    for (int l = 0; l <= 5; l++) {
      if (check(F[a[i]][a[i + 1]][l].second)) {
        cc = 1;
        Sum += F[a[i]][a[i + 1]][l].first;
        break;
      }
    }
    if (!cc) return 1e15;
  }
  return Sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> c[i][j];
  for (int i = 1; i <= n; i++) a[i] = 1e9;
  a[0] = 0;
  a[k / 2] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      for (int l = 0; l <= 6; l++) F[i][j][l].first = 1e15;
      for (int t = 1; t < n; t++)
        if (i != t && j != t) {
          F[i][j][6] = make_pair(c[i][t] + c[t][j], t);
          sort(F[i][j], F[i][j] + 7);
        }
    }
  for (int i = 1; i <= 40960000; i++) {
    res = min(res, Calc(i));
  }
  cout << res;
}
