#include <bits/stdc++.h>
using namespace std;
template <typename T>
void UpdateMax(T& a, T b) {
  if (a < b) a = b;
}
template <typename T>
void UpdateMin(T& a, T b) {
  if (a > b) a = b;
}
template <typename T>
inline void read(T& x) {
  x = 0;
  char c = getchar();
  int flag = 1;
  while (!isdigit(c)) {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= flag;
}
template <typename T>
void Unique(vector<T>& vec) {
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
template <typename T>
void Relabel(vector<T>& vec, T& value) {
  value = lower_bound(vec.begin(), vec.end(), value) - vec.begin() + 1;
}
template <typename T, typename V>
void Print(const pair<T, V>& x) {
  cout << x.first << " @ " << x.second << " | ";
}
template <typename T>
void Print(const T& x) {
  cout << x << " ";
}
template <typename T>
void Pcon(const T& x) {
  cout << "\nsize: " << x.size() << endl;
  for (const auto& item : x) Print(item);
}
std::vector<int> LABS;
template <typename T>
void Print(const T* x, int offset, int loop) {
  for (int i = 0; i <= loop; i++) {
    cout << "[";
    for (int item : LABS) cout << item - offset << ",";
    cout << i - offset << "]:";
    cout << x[i] << " ";
  }
}
template <typename T, typename... Args>
void Print(const T* f, int offset, int loop, Args... args) {
  for (int i = 0; i <= loop; i++) {
    LABS.push_back(i);
    Print(f[i], offset, args...);
    cout << endl;
    LABS.pop_back();
  }
}
int n, k;
int a[15], b[15];
int vis[85];
int w[85][85];
int Pre[85];
long long ans;
clock_t Time;
bool notValid() {
  int version = rand() % 1000;
  for (int i = 0; i <= k; i++) {
    if ((vis[b[i]] >> 10) == version && ((vis[b[i]] & 1023) - i) & 1)
      return true;
    vis[b[i]] = (version << 10) + i;
  }
  return false;
}
long long value(int* x) {
  long long cnt = 0;
  for (int i = 1; i <= k; i++) cnt += w[x[i - 1]][x[i]];
  return cnt;
}
void dfs(int u, int cnt, long long cost, int version) {
  if (cost + Pre[u] >= ans) return;
  if (cnt == k) {
    UpdateMin(ans, cost + w[u][0]);
    return;
  }
  if (1000 * (clock() - Time) >= 2990 * ((clock_t)1000)) {
    cout << ans << endl;
    exit(0);
  }
  for (int i = n - 1; i >= 0; --i) {
    if ((vis[i] >> 10) == version && ((vis[i] & 1023) - cnt) & 1) continue;
    int tmp = vis[i];
    vis[i] = (version << 10) + cnt;
    dfs(i, cnt + 1, cost + w[u][i], version);
    vis[i] = tmp;
  }
}
int main() {
  srand(233);
  Time = clock();
  ans = 1000000000ll;
  cin.sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    Pre[i] = w[i][i] = 1000000000ll;
    for (int j = 0; j < n; ++j) cin >> w[i][j];
    for (int j = 0; j < n; ++j) UpdateMin(Pre[i], w[i][j]);
  }
  for (int i = 1; i < k; i++) {
    a[i] = rand() % n;
  }
  double t = 100000000000 * n * n;
  while (t > 1e-9) {
    memcpy(b, a, sizeof(int) * (k + 1));
    bool ret;
    do {
      int pos = rand() % (k - 1) + 1;
      b[pos] = rand() % n;
      ret = notValid();
    } while (ret);
    const auto& va = value(a);
    const auto& vb = value(b);
    UpdateMin(ans, vb);
    double de = va - vb;
    if (de > 0 || exp(de / t) > (rand() % 1000) * 0.001)
      memcpy(a, b, sizeof(int) * (k + 1));
    t = t * 0.99999;
    if (1000 * (clock() - Time) >= 800 * ((clock_t)1000)) break;
  }
  int version = rand() % 1000;
  vis[0] = (version << 10) + 0;
  dfs(0, 1, 0, version);
  cout << ans << endl;
}
