The dragon keepers of Dragonland are reorganizing a large rectangular plot of land, divided into square cells of the same size, arranged in $$$N$$$ rows and $$$M$$$ columns. Some cells contain obstacles, such as mountains and lava pits, while the remaining cells are free spaces, each inhabited by a dragon.
To give the environment a fresh look without disrupting the group's dynamics, the keepers drew the current position of all the dragons on a transparent magic scroll, so that each free cell of the land corresponds to a mark on the scroll. They plan to relocate the dragons using this same scroll as a template. To do this, the keepers may freely manipulate the scroll on the table: they can rotate it in any direction or even flip it over (looking through the back of the transparent sheet).
A new arrangement is considered valid if the scroll aligns perfectly with the original boundaries of the land and if all the dragon marks fall exactly on free cells. Obviously, no dragon can be placed on an obstacle.
Your task is to compute the total number of valid ways to align the scroll to the land. Each distinct physical orientation of the scroll is counted as a different way, even if two orientations make the marks fall on exactly the same cells. The initial orientation, with the scroll neither rotated nor flipped, already counts as one valid way.
The first line of input contains two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N, M \leq 1000$$$), representing the dimensions of the land.
Each of the following $$$N$$$ lines contains $$$M$$$ characters, describing the land:
Print a single line containing an integer: the number of valid ways to align the scroll to the land.
3 3..#...###
1
3 3.#....#.#
2
2 4........
4