Praveen went crazy yesterday and created an arbitrary matrix consisting of 0, 1 or 2. There was no rule observed in forming this matrix. But then he made up some rules himself.
If there are adjacent 1′s, they are said to be connected. Similarly, if there are adjacent 2′s, they are said to be connected. Here adjacent means all the surrounding positions along with the diagonal positions.
Now given a matrix of 0, 1 or 2, do your computation according to the following rules:
Input format
First line of input contains a positive integer N, the size of matrix. Then N line follows, each containing N integers which are either 0, 1 or 2.
Output format
Print a single line containing the output according to the rule mentioned. Clearly, the output can only be 0, 1, 2 or AMBIGUOUS.
Input constraint
1<=N<=100
Example
4
0 0 0 0
2 0 1 0
0 2 1 2
0 1 2 0
Here the output is 2, as there is a connected path of 2 from first column to last column.
In the sample input, there is a connected path of 1 from first row to last row, and there is a connected path of 2 from first column to last column as well. So, the result is ′AMBIGUOUS′.