#include <bits/stdc++.h>
using namespace std;
const int N = 85;
int n, k, ver[12], dist[N][N];
vector<pair<int, int> > adj[N], minpath[N][N];
int res;
bool vis[N];
void backtrack(int i) {
  if (i > k) {
    for (int id = 1; id <= k + 1; id += 2) vis[ver[id]] = true;
    int id1 = 1;
    int cost = 0;
    while (id1 < k) {
      int u = ver[id1];
      int id2 = id1 + 2;
      int v = ver[id2];
      bool have = false;
      for (auto& x : minpath[u][v]) {
        if (!vis[x.second]) {
          have = true;
          cost += x.first;
          break;
        }
      }
      if (!have) cost = 1e9;
      id1 += 2;
    }
    res = min(res, cost);
    for (int id = 1; id <= k + 1; id += 2) vis[ver[id]] = false;
    return;
  }
  for (int id = 1; id <= n; id++) {
    ver[i] = id;
    backtrack(i + 2);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) cin >> dist[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;
        minpath[i][j].push_back(make_pair(dist[i][k] + dist[k][j], k));
      }
      sort(minpath[i][j].begin(), minpath[i][j].end());
      while (minpath[i][j].size() > 6) minpath[i][j].pop_back();
    }
  }
  res = 1e9;
  ver[1] = 1;
  ver[k + 1] = 1;
  backtrack(3);
  cout << res;
}
