#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m, d[100][100], f[20][100], pos[100], ans;
vector<int> p[2];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &d[i][j]);
  int T = 8000;
  ans = INF;
  while (T--) {
    p[0].clear();
    p[1].clear();
    int x;
    for (int i = 1; i <= n; i++) {
      x = i == 1 ? 0 : rand() % 2;
      p[x].push_back(i);
      pos[i] = x;
    }
    memset(f, 0x3f, sizeof(f));
    f[m][1] = 0;
    for (int i = m - 1; i >= 1; i--)
      for (auto j : p[i % 2]) {
        f[i][j] = INF;
        for (auto k : p[1 - pos[j]])
          f[i][j] = min(f[i][j], f[i + 1][k] + d[j][k]);
      }
    for (auto k : p[1]) ans = min(ans, f[1][k] + d[1][k]);
  }
  printf("%d\n", ans);
  return 0;
}
