#include <bits/stdc++.h>
using namespace std;
const int N = 85, mod = int(1e9) + 7;
int n, k, a[N][N], used[N], v[N], t[90];
pair<int, int> d[N][N][N];
long long ans;
int get(int a, int b) {
  for (int i = 1; i <= n; i++) {
    if (!used[d[a][b][i].second]) return d[a][b][i].first;
  }
  return mod;
}
int num = 0;
void rec(int id) {
  if (id == k + 1) {
    long long res = 0;
    int mn = n + 1;
    for (int i = 2; i <= k; i++) mn = min(mn, v[i]);
    for (int i = 1; i < k; i++) {
      res += get(v[i], v[i + 1]);
    }
    res += get(v[k], 1);
    ans = min(ans, res);
    return;
  }
  for (int i = 1; i <= n; i++) {
    used[i]++;
    v[id] = i;
    rec(id + 1);
    used[i]--;
  }
}
void tup(int id) {
  if (id == 2 * k + 1) {
    long long res = 0;
    memset(t, 0, sizeof(t));
    for (int i = 1; i <= 2 * k; i += 2) {
      t[v[i]] = 1;
    }
    for (int i = 2; i <= 2 * k; i += 2) {
      if (t[v[i]]) return;
    }
    for (int i = 1; i < 2 * k; i++) {
      res += a[v[i]][v[i + 1]];
    }
    res += a[v[2 * k]][1];
    if (res == 8) {
      for (int i = 1; i <= 2 * k; i++) {
        cerr << v[i] << " ";
      }
      cerr << endl;
    }
    ans = min(ans, res);
    return;
  }
  for (int i = 1; i <= n; i++) {
    v[id] = i;
    tup(id + 1);
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  k /= 2;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int m = 0;
      for (int k = 1; k <= n; k++) {
        int c = a[i][k] + a[k][j];
        d[i][j][k] = make_pair(c, k);
      }
      sort(d[i][j] + 1, d[i][j] + n + 1);
    }
  }
  ans = mod;
  v[1] = 1;
  used[1]++;
  rec(2);
  cout << ans << endl;
  return 0;
}
