Farmer John is helping turn his large field into a ski track for the upcoming Mu-Olympics. The field has dimensions M x N (1 <= M,N <=100) and its target final state is described by a lattice of M x N characters such as:
RSRSSS
RSRSSS
RSRSSS
Each symbol describes the state of the snow in that area. R – rough, S– smooth (the organizers believe that in this case - alternating rough and smooth sections, the race will be more interesting).
To accomplish this task, the FD plans to modify its tractor so that it can "stamp" any B x B (B<=M,B<=N) piece of rough snow or smooth snow.
The FD wants to make B as big as possible. With B=1, he can prepare the field by stamping squares individually according to the given final state. However, for larger values of B, it may not be possible to complete the task. Each square of the field must be processed by a tractor. It is not possible to leave a field cell in its original state.
Help the FD to determine the maximum possible value of B that he can successfully use.
INPUT FORMAT:
* Line 1: Two space-separated integers M and N.
* Lines 2..M+1: M lines of exactly N characters (each R or S),
describing the desired final state of the field.
OUTPUT FORMAT:
* Line 1: The maximum value of B that the FD can use to create the desired field.
Enter |
Output |
36
RSRSSS
RSRSSS
RSRSSS
|
3 |
OUTPUT DETAILS:
The FD can stamp R on columns 1-3, then S on columns 2-4, then R on columns 3-5, and finally S in columns 4-6.