#include <bits/stdc++.h>
using namespace std;
int n;
int a[85][85];
int vis[85];
int path[100], x = 0;
int ans = 2e9;
vector<pair<int, int> > dist[85][85];
void dfs(int k) {
  if (k == 0) {
    path[x++] = 1;
    int res = 0;
    for (int i = 1; i < x; i++) {
      int u = path[i - 1], v = path[i];
      bool ok = 0;
      for (int j = 0; j < (int)(dist[u][v]).size(); j++) {
        if (vis[dist[u][v][j].second] == 0) {
          res += dist[u][v][j].first;
          ok = 1;
          break;
        }
      }
      if (!ok) {
        x--;
        return;
      }
    }
    ans = min(ans, res);
    x--;
  } else {
    for (int i = 1; i <= n; i++) {
      path[x++] = i;
      vis[i]++;
      dfs(k - 1);
      vis[i]--;
      x--;
    }
  }
}
int main() {
  int k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        if (i != k && j != k)
          dist[i][j].emplace_back(make_pair(a[i][k] + a[k][j], k));
      }
      sort((dist[i][j]).begin(), (dist[i][j]).end());
    }
  }
  path[x++] = 1;
  vis[1]++;
  dfs(k / 2 - 1);
  printf("%d\n", ans);
}
