#include <bits/stdc++.h>
using namespace std;
const int N = 87, INF = 2e9;
int c[N][N];
vector<pair<int, int>> best[N][N];
int ans = INF;
int n, k;
int cur[N];
int sz = 0;
bool active[N];
void go() {
  if (sz == k / 2) {
    for (int i = 0; i < sz; i++) active[cur[i]] = 1;
    cur[sz] = cur[0];
    int curans = 0;
    int bst = INF;
    for (int i = 0; i < k / 2; i++) {
      int u = cur[i], v = cur[i + 1];
      for (auto pr : best[u][v])
        if (!active[pr.second]) {
          bst = pr.first;
          break;
        }
      if (bst == INF) {
        curans = INF;
        break;
      }
      curans += bst;
    }
    ans = min(ans, curans);
    for (int i = 0; i < sz; i++) active[cur[i]] = 0;
    return;
  }
  cur[sz++] = 0;
  for (int i = 1; i <= n; i++) {
    cur[sz - 1]++;
    go();
  }
  sz--;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> c[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (k == i || k == j) continue;
        best[i][j].push_back({c[i][k] + c[k][j], k});
      }
      sort(best[i][j].begin(), best[i][j].end());
    }
  }
  cur[sz++] = 1;
  go();
  cout << ans << endl;
}
