| II Olympiad of classes at the Mechanics and Mathematics Faculty of MSU in programming 2023. |
|---|
| Finished |
Diana dreamed of a strange black and white field, in which each cell is painted either black or white. Diana immediately came up with the idea of building a wall at the junction of two cells, but only if they are of different colors; it is not allowed to build walls on the border of the field.
But now she wonders what is the length of the side of the largest square that can be enclosed by walls according to the described rules. Only you can save her by telepathically sending the answer to her dream. Hurry up! Diana is about to wake up and go to school.
If it is impossible to enclose a square, output 0.
The first line contains two natural numbers $$$n, m$$$ $$$(3 \le n, m; n \cdot m \le 3 \cdot 10^5 )$$$ — the dimensions of the field. Then $$$n$$$ lines of length $$$m$$$ are entered, describing the field.
Output a single number - the length of the side of the largest square.
5 6 BBBBWB WBWWBW BWBWBB BWWBBW WBWBBW
2
4 4 WBWB BWWW WWWB BWBW
0
3 3 BWW WBW WWB
1
The picture corresponds to the first example, the desired square with a side of 2 is highlighted, it is obvious that a larger square cannot be enclosed:

| Name |
|---|


