#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<vector<vector<pair<int, int>>>> d;
vector<int> cur, used(100, 0);
const int inf = 1e9;
int n, k;
int solve() {
  if ((int)cur.size() == k / 2) {
    cur.push_back(0);
    int s = k / 2 + 1, ret = 0;
    for (auto i : cur) used[i] = 1;
    for (int i = 0; i < s - 1; ++i) {
      int u = cur[i], v = cur[i + 1], dist = inf;
      for (int j = 0; j < (int)d[u][v].size(); ++j) {
        if (!used[d[u][v][j].second]) {
          dist = d[u][v][j].first;
          break;
        }
      }
      ret += dist;
      ret = min(ret, inf);
    }
    for (auto i : cur) used[i] = 0;
    cur.pop_back();
    return ret;
  }
  int ret = inf;
  for (int i = 0; i < n; ++i) {
    cur.push_back(i);
    ret = min(ret, solve());
    cur.pop_back();
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cin >> n >> k;
  g.resize(n, vector<int>(n));
  d.resize(n, vector<vector<pair<int, int>>>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> g[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int m = 0; m < n; ++m) {
        if (m == i || m == j) continue;
        d[i][j].push_back({g[i][m] + g[m][j], m});
      }
      sort(d[i][j].begin(), d[i][j].end());
    }
  }
  cur.push_back(0);
  cout << solve() << '\n';
}
