//4697
import java.util.*;
public class Main {
static int map[][];
static boolean visit[][];
static int n;
static int[] res;
static int white = 0;
static int area = 0;
static int max;
static int h;
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
n = s.nextInt();
map = new int[n][n];
visit = new boolean[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
map[i][j] = s.nextInt();
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < n; j++) {
// System.out.print(map[i][j]+" ");
// }
// System.out.println(" ");
// }
max = map[0][0];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (map[i][j] > max)
max = map[i][j];
}
}
res = new int[max];
for (h = 1; h <= max; h++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (map[i][j] > h && !visit[i][j]) {
white = 0;
dfs(i, j, h);
if (white >= 1) {
area++;
}
res[h - 1] = area;
}
if(map[i][j]==max) {
res[max-1]=1;
}
}
}
for(int a=0;a<n;a++) {
for(int b=0; b<n; b++) {
visit[a][b]=false;
}
}
area=0;
}
int max2 = 0;
for (int i = 0; i < max; i++) {
if(res[i]>max2) max2=res[i];
}
System.out.println(max2);
//
// for (int i = 0; i < max; i++) {
// System.out.println("["+(i+1)+"]"+res[i]);
// }
}
public static void dfs(int x, int y, int num) {
if (x >= 0 && y >= 0 && x < n && y < n && map[x][y] > num && !visit[x][y]) {
//System.out.println("i=" + x + " j=" + y + " white=" + white + " area= " + area);
white++;
visit[x][y] = true;
dfs(x, y - 1, num);
dfs(x, y + 1, num);
dfs(x - 1, y, num);
dfs(x + 1, y, num);
}
}
}
//4572
import java.util.*;
public class Main {
static int map[][];
static int m;
static int n;
static int k;
static int color=0;
static int area=0;
static int[] res;
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
m = s.nextInt();//5
n = s.nextInt();//7
k = s.nextInt();//3
int a = 0,b = 0,c = 0,d = 0;
map = new int[m+2][n+2];
res = new int[m*n];
for(int q=0; q<k; q++) {
a = s.nextInt();
b = s.nextInt();
c = s.nextInt();
d = s.nextInt();
for (int i = b; i < d; i++) {
for (int j = a; j < c; j++) {
map[i+1][j+1] = 1;
}
}
}
//////////////////////////////////////////////////////
//n=7
// for(int i=0; i<n+2;i++) {
// map[0][i]=1;
// map[m+1][i]=1;
// }
//
// //m=5
// for(int i=0; i<m+2;i++) {
// map[i][0]=1;
// map[i][n+1]=1;
// }
//
// for(int i=0;i<m+2;i++) {
// for(int j=0; j<n+2;j++) {
// System.out.print(map[i][j]+" ");
// }
// System.out.println(" ");
// }
/////////////////////////////////////////////////
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (map[i][j] == 0) {
dfs(i, j,map[i][j]);
if(color>=1)
area++;
color=0;
}
}
}
Arrays.sort(res);
System.out.println(area);
for(int i=0; i<res.length; i++){
if(res[i] == 0){
}else{
System.out.print(res[i]+" ");
}
}
}
public static void dfs(int x, int y, int num) {
if (x >= 1 && y >= 1 && x <= m && y <= n && map[x][y]==0) {
//System.out.println("i=" + x + " j=" + y + " color=" + color + " area= " + area);
color++;
res[area]++;
map[x][y]=1;
dfs(x, y - 1, num);
dfs(x, y + 1, num);
dfs(x - 1, y, num);
dfs(x + 1, y, num);
}
}
}
import java.util.*;
public class Point{
int x, y;
Point(int x,int y)
{
this.x=x;
this.y=y;
}
}
public class Main {
static int map[][];
static boolean visit[][];
static ArrayList<Integer> row=new ArrayList();
static ArrayList<Integer> col=new ArrayList();
static int m;
static int n;
static int day=0;//bfs돈 횟수?
static int cnt;//익은 토마토 수
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
m = s.nextInt();//6 가로 col
n = s.nextInt();//4 세로 row
map = new int[n][m];//[4][6]
visit = new boolean [n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
map[i][j] = s.nextInt();
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < m; j++) {
// System.out.print(map[i][j]+" ");
// }
// System.out.println(" ");
// }
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (map[i][j] == 1 &&!visit[i][j]) {
cnt++;
row.add(i);
col.add(j);
bfs(i,j);
}
}
}
if (cnt==m*n) System.out.println(0);//모두 익음
if (cnt==0) System.out.println(-1);// 모두 익지 않음
System.out.println(cnt);
System.out.println(day);
}
public static void bfs(int x, int y){
Queue<Point> queue = new LinkedList<Point>();
queue.add(new Point(x,y));
visit[x][y] = true;
while (!queue.isEmpty()){
}
}
}