#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
void min_self(int &a, int b) { a = min(a, b); }
int main() {
  int n = nxt(), k = nxt();
  vector<vector<int> > matrix(n, vector<int>(n));
  for (int i = 0; i < n; i++)
    generate((matrix[i]).begin(), (matrix[i]).end(), nxt);
  int ans = INT_MAX;
  for (int _ = 0; _ < 20 * 512; _++) {
    vector<vector<int> > dp(k + 1, vector<int>(n, INF));
    vector<int> col(n);
    for (int i = 0; i < n; i++) col[i] = rand() % 2;
    col[0] = 0;
    dp[0][0] = 0;
    for (int i = 0; i < k; i++) {
      for (int u = 0; u < n; u++)
        for (int v = 0; v < n; v++) {
          if (col[v] != col[u]) {
            min_self(dp[i + 1][v], dp[i][u] + matrix[u][v]);
          }
        }
    }
    min_self(ans, dp[k][0]);
  }
  printf("%d\n", ans);
  return 0;
}
