#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
int main() {
  int n, k;
  cin >> n >> k;
  k /= 2;
  vector<vector<int>> a(n, vector<int>(n, 0));
  for (int u = 0; u < n; u++)
    for (int v = 0; v < n; v++) cin >> a[u][v];
  vector<vector<vector<pair<int, int>>>> d(n,
                                           vector<vector<pair<int, int>>>(n));
  for (int u = 0; u < n; u++)
    for (int v = 0; v < n; v++) {
      for (int w = 1; w < n; w++)
        if (w != u && w != v) d[u][v].emplace_back(a[u][w] + a[w][v], w);
      sort(d[u][v].begin(), d[u][v].end());
      d[u][v].resize(min((int)d[u][v].size(), k));
    }
  int res = k * inf;
  vector<int> c(k + 1, 0);
  vector<char> f(n + 1, 0);
  f[0] = k + 1;
  for (; c.back() == 0;) {
    int s = 0;
    for (int i = 0, j; i < k; i++) {
      int x = inf;
      int u = c[i];
      int v = c[i + 1];
      for (auto &y : d[u][v])
        if (!f[y.second]) {
          x = y.first;
          break;
        }
      s += x;
    }
    res = min(res, s);
    f[c[1]]--;
    c[1]++;
    f[c[1]]++;
    for (int i = 1; c[i] == n; i++) {
      f[c[i]]--;
      c[i] = 0;
      f[c[i]]++;
      f[c[i + 1]]--;
      c[i + 1]++;
      f[c[i + 1]]++;
    }
  }
  cout << res << endl;
  return 0;
}
