Avelino has a mosaic on one wall of his house. The mosaic is very old and is made of small colored tiles. Over the years a few tiles came loose and left holes.
Avelino wants to restore the mosaic by covering the holes with new tiles. To spend less, he buys tiles of a single color. He can pick one of the colors already in the mosaic, or a color the mosaic does not contain.
A mosaic should not have very large areas of one color. To keep more detail, Avelino picks the color so that the size of the smallest monochromatic area is as small as possible. Several colors can reach that value. An area is monochromatic if every tile in it has the same color. Two adjacent tiles belong to the same area if they have the same color, and two tiles are adjacent if they share a side.
Look at the first example. There are three areas of color 1 (one of size 3 and two of size 2), one area of color 2 (size 3) and one area of color 3 (size 7). Picking color 2 makes the smallest monochromatic area have size 2. Picking color 1 makes it 3.
Write a program that prints the smallest size the smallest monochromatic area can have.