#include <bits/stdc++.h>
using namespace std;
const int N = 80 + 3, K = 11;
vector<int> v;
vector<pair<long long, int> > t[N][N];
int vis[N];
int n, k;
long long ans = 2e18;
void kill() {
  long long tmp = 0, z = 0;
  for (int i = 1; i < v.size(); i++) {
    for (auto it : t[v[i - 1]][v[i]]) {
      if (vis[it.second]) continue;
      tmp += it.first;
      z++;
      break;
    }
  }
  if (v.size() + z < k) tmp = 2e18;
  ans = min(ans, tmp);
}
void solve(int idx) {
  if (idx == (k - 2) / 2) {
    v.push_back(1);
    kill();
    v.pop_back();
    return;
  }
  for (int i = 1; i <= n; i++) {
    v.push_back(i);
    vis[i]++;
    solve(idx + 1);
    vis[i]--;
    v.pop_back();
  }
}
long long mat[N][N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  v.push_back(1);
  vis[1] = 1;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> mat[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        t[i][j].push_back({mat[i][k] + mat[k][j], k});
      }
      sort(t[i][j].begin(), t[i][j].end());
    }
  }
  solve(0);
  cout << ans;
  return 0;
}
