D. Dragons in Harmony
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

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.

Input

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:

  • The character '.' indicates free land, where a dragon lives.
  • The character '#' indicates an obstacle.
Output

Print a single line containing an integer: the number of valid ways to align the scroll to the land.

Examples
Input
3 3
..#
...
###
Output
1
Input
3 3
.#.
...
#.#
Output
2
Input
2 4
....
....
Output
4