#include <bits/stdc++.h>
using namespace std;
inline void fileio(const char* in, const char* out) {
  freopen(in, "r", stdin);
  freopen(out, "w", stdout);
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<ll> VL;
const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld EPS = 1e-9, PI = acos(-1);
const int N = 81;
int n, k;
int d[N][N];
vector<pii> d2[N][N];
int ans = INF;
vector<int> path;
int used[N];
void check() {
  int a = 0;
  assert(path.front() == 0);
  assert(path.back() == 0);
  for (int i = 0; i < path.size() - 1; i++) {
    int u = path[i];
    int v = path[i + 1];
    auto it = d2[u][v].begin();
    while (it != d2[u][v].end() && used[it->second]) {
      ++it;
    }
    if (it == d2[u][v].end()) return;
    a += it->first;
  }
  ans = min(ans, a);
}
void dfs(int i) {
  path.push_back(i);
  used[i]++;
  if (path.size() == k / 2 + 1) {
    assert(path.back() == 0);
    check();
  } else if (path.size() == k / 2) {
    dfs(0);
  } else {
    for (int v = 0; v < n; ++v) {
      dfs(v);
    }
  }
  used[path.back()]--;
  path.pop_back();
}
int main() {
  atexit([]() { cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  memset(used, 0, sizeof used);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> d[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int u = 0; u < n; ++u) {
      if (u == i) continue;
      for (int v = 0; v < n; ++v) {
        if (v == i) continue;
        d2[u][v].emplace_back(d[u][i] + d[i][v], i);
      }
    }
  }
  for (int u = 0; u < n; ++u) {
    for (int v = 0; v < n; ++v) {
      sort(d2[u][v].begin(), d2[u][v].end());
    }
  }
  cerr << "pre: " << (ld)clock() / CLOCKS_PER_SEC << endl;
  dfs(0);
  cout << ans << nl;
  return 0;
}
