eolymp
bolt
Try our new interface for solving problems
Problems

Cave Paintings

Cave Paintings

Bessie has become an artist and is creating paintings of caves! Her current work in progress is a grid of height n such that each row of the grid contains exactly m squares. Each square is either empty, filled with rock, or filled with water. Bessie has already painted the squares containing rock, including the entire border of the painting. She now wants to fill some empty squares with water such that if the painting were real, there would be no net motion of water. Define the height of a square in the i-th row from the top to be n + 1i. Bessie wants her painting to satisfy the following constraint:

Suppose that square a is filled with water. Then if there exists a path from a to square b using only empty or water squares that are not higher than a such that every two adjacent squares on the path share a side, then b is also filled with water.

Find the number of different paintings Bessie can make modulo 109 + 7. Bessie may fill any number of empty squares with water, including none or all.

Input

The first line contains two space-separated integers n and m (1n, m1000). Each of the next n lines contains m characters. Each character is either '.' or '#', representing an empty square and a square filled with rock, respectively. The first and last row and first and last column only contain '#'.

Output

Print a single integer: the number of paintings satisfying the constraint modulo 109 + 7.

Example

If a square in the second row is filled with water, then all empty squares must be filled with water. Otherwise, assume that no such squares are filled with water. Then Bessie can choose to fill any subset of the three horizontally contiguous regions of empty squares in the third row. Thus, the number of paintings is equal to 1 + 23 = 9.

Time limit 1 second
Memory limit 128 MiB
Input example #1
4 9
#########
#...#...#
#.#...#.#
#########
Output example #1
9
Source 2020 USACO January Platinum