#include <bits/stdc++.h>
int n, ret;
int e[11][11], q[11][11];
int readMatrix(int r, int c) {
  (r < n && c < n) ? scanf("%d", &e[r][c]) : 0;
  (r >= n) ? 0 : ((c >= n) ? readMatrix(r + 1, 0) : readMatrix(r, c + 1));
  return 0;
}
int initMatrix(int r, int c) {
  (r < n && c < n) ? q[r][c] = e[r][c] : 0;
  (r >= n) ? 0 : ((c >= n) ? initMatrix(r + 1, 0) : initMatrix(r, c + 1));
  return 0;
}
int calc(int w, int u, int v) {
  q[u][v] = (w >= n)
                ? q[u][v]
                : (q[u][v] > q[u][w] + q[w][v] ? q[u][w] + q[w][v] : q[u][v]);
  (w < n ? (u == n ? calc(w + 1, 0, 0)
                   : (v == n ? calc(w, u + 1, 0) : calc(w, u, v + 1)))
         : 0);
  return 0;
}
int calcAll(int u, int v) {
  (u < n && v < n) ? (ret < q[u][v] ? (ret = q[u][v]) : 0) : 0;
  (u < n ? ((v < n) ? calcAll(u, v + 1) : calcAll(u + 1, 0)) : 0);
  return 0;
}
int main() {
  scanf("%d", &n);
  readMatrix(0, 0);
  initMatrix(0, 0);
  ret = 0;
  calc(0, 0, 0);
  calcAll(0, 0);
  printf("%d\n", ret);
}
