#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int delta[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool isVisited[101][101];
int buffer[101][101];
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
int n;
cin >> n;
for (auto i=0; i<n; i++){
for (auto j=0; j<n; j++){
cin >> buffer[i][j];
}
}
int answer = 0;
for (auto height = 0; height <= 100; height++ ){
for (auto i=0; i<n; i++){
for (auto j=0; j<n; j++){
isVisited[i][j] = false;
}
}
int safe_area = 0;
for (auto i=0; i<n; i++){
for (auto j=0; j<n; j++){
if ( !isVisited[i][j] && (buffer[i][j] > height)){
safe_area++;
isVisited[i][j] = true;
queue<pair<int, int>> q;
q.push(make_pair(i,j));
while (!q.empty()){
auto top = q.front();
q.pop();
for (auto k=0; k<4; k++){
auto next_x = top.first + delta[k][0];
auto next_y = top.second + delta[k][1];
if (0 <= next_x && next_x < n && 0 <= next_y && next_y < n){
if (!isVisited[next_x][next_y] && (buffer[next_x][next_y] > height)){
isVisited[next_x][next_y] = true;
q.push(make_pair(next_x,next_y));
}
}
}
}
}
}
}
answer = max(answer,safe_area);
}
cout << answer;
return 0;
}