#include <bits/stdc++.h>
using namespace std;
int m[200][200], ma, n;
void buff() {}
void loop(int i, int j) {
  cin >> m[i][j];
  i = (j + 1 == n) ? i + 1 : i;
  j = (j + 1 == n) ? 0 : j + 1;
  ((i == n) ? buff() : loop(i, j));
}
void max_v(int i, int j) {
  ma = max(ma, ((i != j) ? m[i][j] : ma));
  i = (j + 1 == n) ? i + 1 : i;
  j = (j + 1 == n) ? 0 : j + 1;
  ((i == n) ? buff() : max_v(i, j));
}
void floyd(int k, int i, int j) {
  m[i][j] = min(m[i][k] + m[k][j], m[i][j]);
  i = (j + 1 == n) ? i + 1 : i;
  k = (i == n) ? k + 1 : k;
  j = (j + 1 == n) ? 0 : j + 1;
  i = (i == n) ? 0 : i;
  ((k == n) ? buff() : floyd(k, i, j));
}
int main() {
  cin >> n;
  ma = 0;
  loop(0, 0);
  floyd(0, 0, 0);
  max_v(0, 0);
  cout << ma << endl;
  return 0;
}
