#include <bits/stdc++.h>
const int maxn = 15;
int G[maxn][maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &G[i][j]);
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        G[i][j] = std::min(G[i][j], G[i][k] + G[k][j]);
  int maxx = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) maxx = std::max(maxx, G[i][j]);
  printf("%d\n", maxx);
  return 0;
}
