#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void chkmn(int& a, int b) {
  if (a > b) a = b;
}
const int N = 88;
int k;
int g[N][N], gg[6][N][N];
vector<int> v[2];
int solve() {
  if (v[1].empty()) return inf;
  int n = (int)(v[0]).size();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      gg[0][i][j] = inf;
      for (int x : v[1]) chkmn(gg[0][i][j], g[v[0][i]][x] + g[x][v[0][j]]);
    }
  }
  for (int i = 1; (1 << i) <= k; ++i) {
    for (int a = 0; a < n; ++a) {
      for (int b = 0; b < n; ++b) {
        gg[i][a][b] = inf;
        for (int c = 0; c < n; ++c)
          chkmn(gg[i][a][b], gg[i - 1][a][c] + gg[i - 1][c][b]);
      }
    }
  }
  for (int i = 0; i < 3; ++i) {
    if ((1 << i) == k) return gg[i][0][0];
    for (int j = 0; j < 3; ++j) {
      if ((1 << i) + (1 << j) != k) continue;
      int ans = inf;
      for (int x = 0; x < n; ++x) chkmn(ans, gg[i][0][x] + gg[j][x][0]);
      return ans;
    }
  }
}
int main() {
  int n;
  scanf("%d %d", &n, &k);
  k /= 2;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) scanf("%d", &g[i][j]);
  int ans = inf;
  for (int it = 0; it < 5000; ++it) {
    v[0] = {0};
    v[1].clear();
    for (int i = 1; i < n; ++i) v[rng() % 2].push_back(i);
    ans = min(ans, solve());
  }
  printf("%d\n", ans);
}
