#include <bits/stdc++.h>
using namespace std;
int x[15][15];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      x[i][j] = 100000000;
    }
    x[i][i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> x[i][j];
    }
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        x[i][j] = min(x[i][j], x[i][k] + x[k][j]);
      }
    }
  }
  int maxx = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      maxx = max(maxx, x[i][j]);
    }
  }
  cout << maxx << endl;
}
