Polyomino Powers

No attempts yetTime limit1sMemory limit128 MB

Problem

A polyomino is a shape whose basic building block is the unit square. It is a connected figure formed by joining one or more identical squares placed at distinct positions on the regular square grid, so that every square is connected to every other square through a chain of shared edges (shapes joined only at corners are not allowed). The best-known polyominoes are the seven tetrominoes made of four squares (famous from the game Tetris) and the domino made of two squares.

Some polyominoes can be built by taking several copies of a single smaller polyomino and gluing them — using translation only, without rotation or reflection — at different positions in the plane. Such a polyomino is called a power of the smaller one. Formally, a polyomino is a $k$-power if it can be exactly covered, without overlaps, by $k$ translated copies of one smaller polyomino.

Input

The first line contains two positive integers $h$ and $w$ ($h, w \le 10$).

Each of the next $h$ lines contains $w$ characters describing an $h \times w$ grid. Each character is either . or X; an X marks a cell that belongs to the polyomino and a . marks empty space. The X cells form a single polyomino (they are edge-connected).

Output

Print the smallest integer $k$ with $2 \le k \le 5$ such that the given polyomino is a $k$-power — that is, the smallest number of translated copies of one smaller polyomino that exactly cover it. If no such $k$ exists, print No solution instead.