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