#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using cd = complex<double>;
ll adj[(ll)(8e1 + 7)][(ll)(8e1 + 7)], n, k, ch[(ll)(8e1 + 7)],
    cc = 0, ans = (ll)(1e9 + 7);
vector<pair<ll, ll>> vp[(ll)(8e1 + 7)][(ll)(8e1 + 7)];
void rec(ll l, vector<ll>& vv) {
  if (!l) {
    ll pr = 0, an = 0;
    vv.push_back(0);
    for (ll x : vv) {
      ch[x] = cc;
    }
    for (ll x : vv) {
      bool fl = 0;
      for (pair<ll, ll> xx : vp[pr][x]) {
        if (ch[xx.second] != cc) {
          an += xx.first;
          fl = 1;
          break;
        }
      }
      if (!fl) {
        cc++;
        vv.pop_back();
        return;
      }
      pr = x;
    }
    vv.pop_back();
    ans = min(ans, an);
    cc++;
    return;
  }
  for (ll i = 0; i < n; i++) {
    vv.push_back(i);
    rec(l - 1, vv);
    vv.pop_back();
  }
}
int main() {
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      cin >> adj[i][j];
    }
    adj[i][i] = (ll)(1e9 + 7);
  }
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      for (ll k = 0; k < n; k++) {
        vp[i][j].push_back(make_pair(adj[i][k] + adj[k][j], k));
      }
      sort(vp[i][j].begin(), vp[i][j].end());
    }
  }
  vector<ll> vx;
  fill(ch, ch + n, -1);
  rec(k / 2 - 1, vx);
  cout << ans << "\n";
}
