#include <bits/stdc++.h>
using namespace std;
double start;
long long not_possible = -1;
long long solve(
    const vector<vector<set<pair<int, int>>>>& from_to_price_element,
    const vector<int>& chose) {
  int total_price = 0;
  for (int i = 0; i < chose.size() - 1; ++i) {
    int a = chose[i];
    int b = chose[i + 1];
    bool find_el = false;
    for (auto& el : from_to_price_element[a][b]) {
      if (find(chose.begin(), chose.end(), el.second) == chose.end()) {
        total_price += el.first;
        find_el = true;
        break;
      }
    }
    if (!find_el) {
      return not_possible;
    }
  }
  return total_price;
}
long long iterate(
    const vector<vector<set<pair<int, int>>>>& from_to_price_element,
    vector<int>& chose, int n) {
  int len = chose.size();
  for (int i = len - 2; len >= 1; --i) {
    if (chose[i] < n - 1) {
      chose[i] += 1;
      break;
    } else {
      chose[i] = 0;
    }
  }
  long long result = solve(from_to_price_element, chose);
  return result;
}
int main(int argc, char* argv[]) {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  start = clock();
  int n, k;
  cin >> n >> k;
  vector<vector<int>> price(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> price[i][j];
    }
  }
  vector<vector<set<pair<int, int>>>> from_to_price_element(
      n, vector<set<pair<int, int>>>(n));
  for (int a = 0; a < n; ++a) {
    for (int b = 0; b < n; ++b) {
      for (int c = 0; c < n; ++c) {
        if (c == a || c == b) {
          continue;
        }
        from_to_price_element[a][b].insert(
            make_pair(price[a][c] + price[c][b], c));
      }
    }
  }
  vector<int> stops;
  for (int i = 0; i < k / 2 - 1; ++i) {
    stops.push_back(0);
  }
  stops.push_back(-1);
  stops.push_back(0);
  int power = (k / 2 - 1);
  int num_iterations = int(pow(n, power));
  long long cheapest_result = 1000000000000;
  for (int i = 0; i < num_iterations; ++i) {
    long long result = iterate(from_to_price_element, stops, n);
    if (result != -1 && cheapest_result > result) {
      cheapest_result = result;
    }
  }
  cout << cheapest_result;
  std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
  return 0;
}
