Appearance Analysis

Given a grid of brick separators and windows, count how many distinct window designs exist, where rotations by multiples of 90 degrees count as the same design.

Medium4ImplementationMatrixStringHash mapNo attempts yetTime limit1sMemory limit512 MB

Problem

You took a photo of a building whose equally sized windows are laid out in neat rows and columns. Some of the windows are painted with curious designs. You want to analyze the photo and count how many distinct designs there are.

The photo is a rectangular grid of characters with rr rows and cc columns. Every window is a rectangle and all windows have the same dimensions. Each cell of a window is either clear (the . character) or painted (the + character). Two windows have the same design if one of them can be rotated by a multiple of 90 degrees and placed on top of the other so that they match exactly. Flipping a window over is not allowed when comparing designs.

Every window is framed by a single line of brick cells (the # character). There is exactly one row of # characters between two consecutive window rows, before the first window row, and after the last window row. In the same way there is exactly one column of # characters between two consecutive window columns, before the first window column, and after the last window column. The number of window rows and the number of window columns are arbitrary, and so are the window dimensions. A window consists of at least one cell, and all windows in the photo have the same dimensions.

Find the number of different window designs in the photo.

Input

The first line contains the number of rows rr and the number of columns cc of the photo (3r,c1113 \le r, c \le 111).

Each of the following rr lines contains a string of cc characters. It describes one row of the photo.

Output

Print the number of different window designs in the photo on one line.