2437 - Pattern Finder
Oceania - South Pacific - 2008/2009
PDF Submit Ranking

 

A number pattern is a sequence of two or more numbers that satisfies a certain rule. For instance, the sequence `` 3, 5, 7, 9,... " is a number pattern that starts with three and jumps by twos. In primary school, number patterns are used as a tool for learning basic arithmetic and problem-solving skills. Finding a number pattern in a grid of integers is Mrs Brown's favourite challenge for her pupils.

Mrs Brown's number pattern challenge for her 2nd grade pupils is to find a number pattern in a grid of integers. The number pattern must start at the smallest value, jumps to an adjacent cell in the grid by adding a fixed positive value, and terminates at the largest value. Two cells are considered adjacent if they share the same row or share the same column.


$\textstyle \parbox{.5\textwidth}{
\begin{center}
\begin{tabular}{\vert c\vert c...
... 9 & 10 & 12 \\
\hline
12 & 14 & 12 & 14 \\
\hline
\end{tabular}\end{center}}$$\textstyle \parbox{.49\textwidth}{
\begin{center}
\begin{tabular}{\vert c\vert ...
... 9 & 10 & 12 \\
\hline
15 & 14 & 12 & 14 \\
\hline
\end{tabular}\end{center}}$


For instance, the grid on the left has a pattern that starts at 4 and jumps by 2 and terminates at the largest value of 14, but no pattern can be found in the grid on the right.

Mrs Brown has a large number of these grids, but she does not have the time to find the correct answer for each one. Your task is to help by writing a program to check the existence of a pattern of the required form in a given grid.

Input 

The input consists of a series of scenarios. The first line in each scenario consists of two positive integers N and M that represent the number of rows and columns in a grid. 1$ \le$N, M$ \le$100 . Each of the following N lines contains M integers that represent the integers in a single row in the grid. The integers are separated by single spaces, and have values that does not exceed 30000.

Input is terminated by a challenge where N and M equal -1.

This challenge should not be processed.

Output 

Output consists of one line for each grid. It will be in one of the following two formats:


At least one pattern exists.
No pattern can be found.

Sample Input 

28 
77 78 79 77 77 77 77 77 
78 79 80 81 82 83 84 85 
-1 -1

Sample Output 

At least one pattern exists.


South Pacific 2008-2009