URI Online Judge | 2246

Tiles

By Maratona de Programação da SBC 2016 BR Brazil

Timelimit: 1

Avelino has a mosaic on one wall of your home. It is a very ancient mosaic, composed of small colored tiles. How is an ancient mosaic, some tiles fell off over the years forming holes.

Now Avelino want to restore the mosaic covering the holes with new tiles. However, to save, Avelino want to buy tiles of a single color to fill the holes. In particular, wants to buy a tiling of the original colors or a color that is not contained in the mosaic.

Being a mosaic, you do not want that have very large areas with the same color. Avelino decided who will choose the color of the tiles trying to make the size of the smallest monochrome area as small as possible, so there is more detail. Note that there may be more than one possible color. A monochromatic area is that all the tiles in it are of the same color. Two adjacent tiles belonging to the same area will have the same color and two tiles are adjacent if they share one side.

See the first example case, there are three color areas (1 a size two size 3 and 2), a color area 2 (size 3) and a color area size of 3 7. A possible answer would be to choose 2 color, causing the monochromatic area is smaller in size 2. If we choose the color of the lower area would be one size 3.

Create a program that prints the size of the smallest possible area.

Input

The first line contains two integers H and L, the height and width of the mosaic, respectively, satisfying 1 ≤ M ≤ 200 and 1 ≤ L ≤ 200. Then M lines each contain integers L, separated by a space, corresponding to the colors of the tiles. An integer of 0 corresponds to a hole and an integer i ≠ 0 corresponds to a tile with the ith color, may range from 1 to 40,000 at most.

Output

Its program should produce a line containing a whole, the size of the smallest area possible.

Input Samples Output Samples

3 8
3 3 3 1 1 0 0 0
3 1 1 0 2 2 0 1
3 3 3 0 0 2 1 1

2

3 7
1 1 0 2 2 1 1
1 1 0 2 2 1 1
1 1 0 0 3 3 3

3

3 6
2 2 2 2 0 2
2 2 2 0 2 2
2 2 2 2 0 2

1