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