#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, dist[110][110];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &dist[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++)
        dist[j][k] = dist[j][k] > dist[j][i] + dist[i][k]
                         ? dist[j][i] + dist[i][k]
                         : dist[j][k];
  int max = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) max = max > dist[i][j] ? max : dist[i][j];
  cout << max << endl;
  return 0;
}
