#include <bits/stdc++.h>
using namespace std;
const int maxn = 80;
int n, k;
int a[maxn][maxn];
vector<pair<int, int>> bestPaths[maxn][maxn];
void getBest(int from, int to) {
  for (int i = 0; i < n; i++) {
    if (i != from && i != to) {
      vector<pair<int, int>> &cur = bestPaths[from][to];
      cur.emplace_back(a[from][i] + a[i][to], i);
      for (int j = (int)cur.size() - 1; j > 0;) {
        if (cur[j - 1] > cur[j]) {
          swap(cur[j - 1], cur[j]);
          j--;
        } else {
          break;
        }
      }
      while (cur.size() > 6) cur.pop_back();
    }
  }
}
int answer;
int takenValues[5];
void dfs(int takenCount) {
  if (takenCount * 2 == k) {
    int curAns = 0;
    for (int i = 0; i < takenCount; i++) {
      int x = takenValues[i];
      int y = takenValues[(i + 1) % takenCount];
      bool any = false;
      for (auto &p : bestPaths[x][y]) {
        bool isOk = true;
        for (int j = 0; j < takenCount; j++) {
          if (takenValues[j] == p.second) {
            isOk = false;
            break;
          }
        }
        if (isOk) {
          curAns += p.first;
          any = true;
          break;
        }
      }
      if (!any) return;
    }
    answer = min(answer, curAns);
    return;
  }
  for (int i = 0; i < n; i++) {
    takenValues[takenCount] = i;
    dfs(takenCount + 1);
  }
}
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) getBest(i, j);
  answer = (int)2e9;
  takenValues[0] = 0;
  dfs(1);
  cout << answer;
}
