#include <bits/stdc++.h>
using namespace std;
enum STATE { IN, OUT, BOUNDRY };
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
int lx[] = {2, 2, -1, 1, -2, -2, -1, 1};
int ly[] = {-1, 1, 2, 2, 1, -1, -2, -2};
const long double eps = 1e-3;
const int N = 6e5 + 10, M = 20 + 10, mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  long long t = gcd(a, b);
  return t ? (a / t * b) : 0;
}
int n, m;
int ar[88][88];
int ans = INT_MAX;
set<pair<int, int>> s[88][88];
int vis[88];
vector<int> v;
void solve(int ind) {
  if (ind == m) {
    int sum = 0;
    for (int i = 1; i < v.size(); ++i) {
      bool ok = 0;
      for (auto e : s[v[i - 1]][v[i]])
        if (!vis[e.second]) {
          sum += e.first;
          ok = 1;
          break;
        }
      if (!ok) return;
    }
    ans = min(ans, sum);
    return;
  }
  if (ind == m - 1) {
    vis[0]++;
    v.push_back(0);
    solve(ind + 1);
    vis[0]--;
    v.pop_back();
    return;
  }
  for (int i = 0; i < n; ++i) {
    vis[i]++;
    v.emplace_back(i);
    solve(ind + 1);
    vis[i]--;
    v.pop_back();
  }
  return;
}
int main() {
  fast_in_out();
  cin >> n >> m;
  m >>= 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> ar[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        if (k != i || k != j) {
          s[i][j].emplace(ar[i][k] + ar[k][j], k);
          if (s[i][j].size() > 5) s[i][j].erase(*s[i][j].rbegin());
        }
  v.push_back(0);
  vis[0] = 1;
  solve(0);
  cout << ans;
  return 0;
}
