from sys import setrecursionlimit
setrecursionlimit(10000)
n = int(input())
grid = []
cnt = 0
visited = [[False for i in range(n)] for i in range(n)]
for _ in range(n):
grid.append(list(map(int, input().split())))
def is_valid(x,y):
if x >= 0 and x < n and y < n and y >= 0:
return True
return False
def dfs(x,y):
if not is_valid(x,y):
return False
if visited[x][y] == False and grid[x][y] != 0:
visited[x][y] = True
dfs(x+1,y)
dfs(x-1,y)
dfs(x,y+1)
dfs(x,y-1)
return True
return False
def rain(depth):
global visited
visited = [[False for i in range(n)] for i in range(n)]
for x in range(n):
for y in range(n):
if grid[x][y] <= depth:
grid[x][y] = 0
min_depth = min(min(grid))
max_depth = max(max(grid))
depth = min_depth
answers = [1]
while(depth <= max_depth):
rain(depth)
cnt = 0
for x in range(n):
for y in range(n):
if dfs(x,y):
cnt += 1
answers.append(cnt)
depth += 1
print(max(answers))