#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int read(T& x) {
  x = 0;
  char c = getchar(), f = 1;
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    if (c == -1) return -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  x *= f;
  return 1;
}
template <typename T, typename... Args>
inline int read(T& x, Args&... args) {
  return read(x) + read(args...);
}
template <typename T>
inline int write(T x) {
  if (x < 0) return putchar('-') & write((~x) + 1);
  if (x / 10) return write(x / 10) & putchar(x % 10 | 48);
  return putchar(x | 48);
}
template <typename T>
inline int write(T x, char c) {
  return write(x) + putchar(c);
}
int n, m, k;
inline int seedrand(string s) {
  int seed = 0;
  for (char c : s) seed = seed * 233 + 114514 + 1919810 + c;
  return seed;
}
long long dis[85][85], dp[15][85];
int col[85];
int adpc;
signed main() {
  read(n, k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) read(dis[i][j]);
  srand(seedrand("jzm,xyx,dym,tql,orz"));
  long long ans = 1e18, rep = 3e8 / k / n / n;
  while (rep--) {
    for (int i = 1; i <= n; i++) col[i] = rand() & 1, dp[0][i] = 1e18;
    dp[0][1] = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= n; j++) dp[i][j] = 1e18;
      for (int j = 1; j <= n; j++)
        for (int x = 1; x <= n; x++)
          if (col[x] != col[j])
            dp[i][x] = ((dp[i][x]) < (dp[i - 1][j] + dis[j][x])
                            ? (dp[i][x])
                            : (dp[i - 1][j] + dis[j][x]));
    }
    ans = ((ans) < (dp[k][1]) ? (ans) : (dp[k][1]));
  }
  write(ans, '\n');
}
