#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long p = 1, data = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    data = data * 10 + (ch ^ 48);
    ch = getchar();
  }
  return p * data;
}
inline long long qpow(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = a * r;
    a = a * a;
    b >>= 1;
  }
  return r;
}
inline long long gcd(long long a, long long b) {
  if (!a || !b) return (!a) ? b : a;
  while (b ^= a ^= b ^= a %= b)
    ;
  return a;
}
inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b)
    x = 1, y = 0;
  else {
    exgcd(b, a % b, y, x);
    y -= x * (a / b);
  }
}
const int mod = 1e9 + 7;
int mp[81][81], dp[81][11], col[81];
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) mp[i][j] = read();
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  srand(2333);
  int ans = 0x3f3f3f3f;
  for (int tot = 1; tot <= 10000; tot++) {
    for (int i = 1; i <= n; i++) col[i] = rand() & 1;
    for (int i = 1; i <= n; i++)
      for (int k = 1; k <= m; k++) dp[i][k] = 0x3f3f3f3f;
    dp[1][0] = 0;
    for (int p = 1; p <= m; p++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          if (col[i] != col[j])
            dp[j][p] = min(dp[j][p], dp[i][p - 1] + mp[i][j]);
    ans = min(ans, dp[1][m]);
  }
  printf("%d\n", ans);
  return 0;
}
