#include <iostream>
using namespace std;
using IntPair = pair<int, int>;
#define MAX 100+1
#define y first
#define x second
IntPair dir[]
{
{1, 0}, // 상
{-1, 0}, // 하
{0, -1}, // 좌
{0, 1} // 우
};
int board[MAX][MAX];
bool vis[MAX][MAX];
int n, ans;
void Reset()
{
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
vis[i][j] = false;
}
}
void DFS(int y, int x, int rain)
{
vis[y][x] = true;
for (int i = 0; i < 4; i++)
{
int ny = y + dir[i].y, nx = x + dir[i].x;
if (ny < 1 ||
ny > n ||
nx < 1 ||
nx > n)
continue;
if (!vis[ny][nx] &&
board[ny][nx] > rain)
DFS(ny, nx, rain);
}
}
void Input()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
cin >> board[i][j];
}
}
void Check()
{
for (int k = 0; k <= 100; k++)
{
int cnt = 0;
Reset();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (board[i][j] > k &&
!vis[i][j])
{
cnt++;
DFS(i, j, k);
}
}
}
if (cnt > ans)
ans = cnt;
}
}
int main()
{
Input();
Check();
cout << ans;
}