#include <bits/stdc++.h>
using namespace std;
int n, m;
int mat[80][80];
vector<pair<int, int> > vec[80][80];
int main() {
  memset(mat, 0x3f, sizeof(mat));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x;
      scanf("%d", &x);
      if (i == j) continue;
      mat[i][j] = x;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 1; k < n; k++) {
        vec[i][j].push_back({mat[i][k] + mat[k][j], k});
      }
      sort(vec[i][j].begin(), vec[i][j].end());
    }
  }
  int ans = 0x3f3f3f3f;
  if (m == 10) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          for (int p = 0; p < n; p++) {
            int now = 0;
            bool updated = false;
            for (auto x : vec[0][i]) {
              if (x.second == i || x.second == j || x.second == k ||
                  x.second == p)
                continue;
              now += x.first;
              updated = true;
              break;
            }
            if (!updated) continue;
            updated = false;
            for (auto x : vec[i][j]) {
              if (x.second == i || x.second == j || x.second == k ||
                  x.second == p)
                continue;
              now += x.first;
              updated = true;
              break;
            }
            if (!updated) continue;
            updated = false;
            for (auto x : vec[j][k]) {
              if (x.second == i || x.second == j || x.second == k ||
                  x.second == p)
                continue;
              now += x.first;
              updated = true;
              break;
            }
            if (!updated) continue;
            updated = false;
            for (auto x : vec[k][p]) {
              if (x.second == i || x.second == j || x.second == k ||
                  x.second == p)
                continue;
              now += x.first;
              updated = true;
              break;
            }
            if (!updated) continue;
            updated = false;
            for (auto x : vec[p][0]) {
              if (x.second == i || x.second == j || x.second == k ||
                  x.second == p)
                continue;
              now += x.first;
              updated = true;
              break;
            }
            if (!updated) continue;
            ans = min(ans, now);
          }
        }
      }
    }
  } else if (m == 8) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          int now = 0;
          bool updated = false;
          for (auto x : vec[0][i]) {
            if (x.second == i || x.second == j || x.second == k) continue;
            now += x.first;
            updated = true;
            break;
          }
          if (!updated) continue;
          updated = false;
          for (auto x : vec[i][j]) {
            if (x.second == i || x.second == j || x.second == k) continue;
            now += x.first;
            updated = true;
            break;
          }
          if (!updated) continue;
          updated = false;
          for (auto x : vec[j][k]) {
            if (x.second == i || x.second == j || x.second == k) continue;
            now += x.first;
            updated = true;
            break;
          }
          if (!updated) continue;
          updated = false;
          for (auto x : vec[k][0]) {
            if (x.second == i || x.second == j || x.second == k) continue;
            now += x.first;
            updated = true;
            break;
          }
          if (!updated) continue;
          ans = min(ans, now);
        }
      }
    }
  } else if (m == 6) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int now = 0;
        bool updated = false;
        for (auto x : vec[0][i]) {
          if (x.second == i || x.second == j) continue;
          now += x.first;
          updated = true;
          break;
        }
        if (!updated) continue;
        updated = false;
        for (auto x : vec[i][j]) {
          if (x.second == i || x.second == j) continue;
          now += x.first;
          updated = true;
          break;
        }
        if (!updated) continue;
        updated = false;
        for (auto x : vec[j][0]) {
          if (x.second == i || x.second == j) continue;
          now += x.first;
          updated = true;
          break;
        }
        if (!updated) continue;
        ans = min(ans, now);
      }
    }
  } else if (m == 4) {
    for (int i = 0; i < n; i++) {
      int now = 0;
      bool updated = false;
      for (int j = 0; j < vec[0][i].size(); j++) {
        if (vec[0][i][j].second == i) continue;
        now += vec[0][i][j].first;
        updated = true;
        break;
      }
      if (!updated) continue;
      updated = false;
      for (int j = 0; j < vec[i][0].size(); j++) {
        if (vec[i][0][j].second == i) continue;
        now += vec[i][0][j].first;
        updated = true;
        break;
      }
      if (!updated) continue;
      ans = min(ans, now);
    }
  } else if (m == 2) {
    ans = vec[0][0][0].first;
  }
  printf("%d\n", ans);
  return 0;
}
