#include<cstdio>
#include<queue>
#include<memory.h>
#include<vector>
using namespace std;
const int dr[] = { 0,0,-1,1 };
const int dc[] = { -1,1, 0,0 };
const int m = 111;
int im[m][m];
int chk[m][m];
int vis[m][m];
int s;
struct pos {
int r, c;
pos(int ir, int ic) : r(ir), c(ic) {}
};
bool is_range_over(int r, int c) {
if (r < 0 || s <= r || c < 0 || s <= c) return true;
return false;
}
int main() {
scanf("%d", &s);
int mx_flow = 101;
for (int r = 0; r < s; r++) {
for (int c = 0; c < s; c++) {
scanf("%d", &im[r][c]);
mx_flow = (mx_flow > im[r][c]) ? mx_flow : im[r][c];
}
} // input
int ans = 0;
vector<pos> vp;
for (int flow = 0; flow <= mx_flow; flow++) {
memset(chk, 0, sizeof(chk));
memset(vis, 0, sizeof(vis));
vp.clear();
for (int r = 0; r < s; r++) {
for (int c = 0; c < s; c++) {
if (im[r][c] <= flow) {
chk[r][c] = 0;
}
else {
chk[r][c] = 1;
vp.push_back(pos(r, c));
}
}
}
int q_ans = 0;
for (auto pp : vp) {
int r = pp.r;
int c = pp.c;
if (chk[r][c] == 0) continue;
if (vis[r][c] == 1) continue;
q_ans++;
queue<pos> Q;
Q.push(pos(r, c));
vis[r][c] = 1;
while (!Q.empty()) {
pos here = Q.front();
Q.pop();
int hr = here.r;
int hc = here.c;
for (int i = 0; i < 4; i++) {
int tr = hr + dr[i];
int tc = hc + dc[i];
if (is_range_over(tr, tc)) continue;
if (vis[tr][tc] == 1) continue;
if (chk[tr][tc] == 1) {
vis[tr][tc] = 1;
Q.push(pos(tr, tc));
}
}
}
}
ans = (ans > q_ans) ? ans : q_ans;
}
printf("%d\n", ans);
return 0;
}