#include <bits/stdc++.h>
const long double PI = acos(-1);
const long double eps = 0.0000000001;
const long long INF = 0x3fffffffffffffff;
unsigned long long seed =
    std::chrono::system_clock::now().time_since_epoch().count() / 1000000;
std::mt19937_64 Rand(seed);
long long n, k, v[85][85], dp[2][85], c[85], ans = INF;
bool now = true, lst = false;
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n >> k;
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= n; ++j) std::cin >> v[i][j];
  while (clock() < 2500) {
    std::for_each(c + 1, c + 1 + n, [&](long long &x) { x = Rand() & 1; });
    std::fill(dp[now] + 1, dp[now] + 1 + n, INF);
    dp[now][1] = 0;
    for (long long i = 1; i <= k; ++i) {
      std::swap(now, lst);
      std::fill(dp[now] + 1, dp[now] + 1 + n, INF);
      for (long long j = 1; j <= n; ++j) {
        for (long long k = 1; k <= n; ++k) {
          if (c[j] != c[k]) {
            dp[now][k] = std::min(dp[now][k], dp[lst][j] + v[j][k]);
          }
        }
      }
    }
    ans = std::min(ans, dp[now][1]);
  }
  std::cout << ans << std::endl;
  return 0;
}
