#include <bits/stdc++.h>
using namespace std;
int f[20][20];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) cin >> f[i][j];
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) ans = max(ans, f[i][j]);
  cout << ans;
  return 0;
}
