#include <bits/stdc++.h>
using namespace std;
long long mat[85][85];
int even[6];
int n, k;
pair<long long, int> dist2[85][85][6];
int ev[85];
long long solve() {
  long long res = 0;
  bool ok = 0;
  for (int i = 0; i < k / 2; i++) {
    for (int j = 0; j < 6; j++) {
      if (dist2[even[i]][even[i + 1]][j].second >= 80) break;
      if (!ev[dist2[even[i]][even[i + 1]][j].second]) {
        res += dist2[even[i]][even[i + 1]][j].first;
        ok = 1;
        break;
      }
    }
  }
  if (ok)
    return res;
  else
    return (long long)1e18;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> mat[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      vector<pair<long long, int> > dists;
      for (int u = 0; u < n; u++) {
        if (u == i || u == j) continue;
        dists.push_back({mat[i][u] + mat[u][j], u});
      }
      sort(dists.begin(), dists.end());
      for (int u = 0; u < min(6, (int)dists.size()); u++)
        dist2[i][j][u] = dists[u];
      for (int u = dists.size(); u < 6; u++) dist2[i][j][u] = {0, 100};
    }
  }
  long long ans = 1e18;
  ev[0] = 1;
  if (k == 2) {
    ans = min(ans, solve());
  } else {
    for (even[1] = 0; even[1] < n; even[1]++) {
      ev[even[1]]++;
      if (k == 4) {
        ans = min(ans, solve());
        ev[even[1]]--;
        continue;
      }
      for (even[2] = 0; even[2] < n; even[2]++) {
        ev[even[2]]++;
        if (k == 6) {
          ans = min(ans, solve());
          ev[even[2]]--;
          continue;
        }
        for (even[3] = 0; even[3] < n; even[3]++) {
          ev[even[3]]++;
          if (k == 8) {
            ans = min(ans, solve());
            ev[even[3]]--;
            continue;
          }
          for (even[4] = 0; even[4] < n; even[4]++) {
            ev[even[4]]++;
            ans = min(ans, solve());
            ev[even[4]]--;
          }
          ev[even[3]]--;
        }
        ev[even[2]]--;
      }
      ev[even[1]]--;
    }
  }
  cout << ans;
  return 0;
}
