#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 85;
const int MAX_K = 15;
int n, k;
int cost[MAX_N][MAX_N];
vector<pair<int, int> > between[MAX_N][MAX_N];
int cur[MAX_K];
int ans = 1e9;
int used[MAX_N];
void updBes() {
  int res = 0;
  for (int idx = 1; idx < k; idx += 2) {
    int lo = 1e9;
    for (pair<int, int>& p : between[cur[idx - 1]][cur[idx + 1]]) {
      if (!used[p.second]) {
        lo = p.first;
        break;
      }
    }
    if (lo == 1e9) return;
    res += lo;
  }
  ans = min(ans, res);
}
void solve(int idx) {
  if (2 * idx >= k - 1) {
    updBes();
  } else {
    for (int i = 0; i < n; i++) {
      cur[2 * idx] = i;
      used[i]++;
      solve(idx + 1);
      used[i]--;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  k++;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> cost[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int u = 0; u < n; u++)
        if (u != i && u != j) {
          between[i][j].push_back(make_pair(cost[i][u] + cost[u][j], u));
        }
      sort(between[i][j].begin(), between[i][j].end());
    }
  }
  cur[0] = 0;
  cur[k - 1] = 0;
  used[0] += 2;
  solve(1);
  return cout << ans << '\n', 0;
  ;
}
