#include <bits/stdc++.h>
using namespace std;
long long dp[85][20];
int color[85];
int c[85][85];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  srand(time(NULL));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> c[i][j];
  long long res = INT_MAX;
  for (int cnt = 1; cnt <= 3000; cnt++) {
    for (int i = 1; i <= n; i++) color[i] = rand() % 2;
    for (int i = 1; i <= n; i++)
      for (int j = 0; j <= k; j++) dp[i][j] = INT_MAX;
    dp[1][0] = 0;
    for (int p = 1; p <= k; p++)
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
          if (color[i] != color[j])
            dp[j][p] = min(dp[j][p], dp[i][p - 1] + c[i][j]);
    res = min(res, dp[1][k]);
  }
  cout << res;
}
