Problem: A grid of r × c is given.
Numbers from 1 to 8 are written on some squares on the grid.


<image>

It is necessary to connect the squares with numbers and the squares with other numbers with a line.
For the squares with numbers written on them, it is necessary to connect lines with other squares as many as the number written on that square.
However, the lines can be connected only in the vertical and horizontal directions, and up to two lines can be connected in one direction.
<image>

It cannot be connected by a line across other numbers.
<image>

In addition, it is not possible to tie them so that they intersect as follows.
<image>

Since the grid is given as input, please count how many ways there are ways to correctly connect all the squares with numbers.



Input

The input is given in the following format.


r c
grid1
..
..
..
gridr-1


gridi is a string of length c, consisting of numbers from 1 to 8 or ".".

Input meets the following constraints
1 ≤ r, c ≤ 10

Output

Divide the answer value by 100,000,007 and output the remainder on one line

Examples

Input

3 3
.1.
1.1
.1.


Output

0


Input

1 3
1.1


Output

1


Input

3 3
4.2
...
2..


Output

1


Input

7 7
2.3.1.1
.......
2......
.......
..3.3..
.......
2.2.4.3


Output

10

Solution (in CPP):

Solution:
#include <iostream>
#include <cstring>
using namespace std;

char g[10][10];

int memo[10][10][3][59049];
int pow3[20];

int H,W;


int dfs(int x,int y,int yoko,int tate){
	if( x == W ){
		if( yoko ) return 0;
		x = 0;
		y++;
	}
	if( y == H ) {
		return tate == 0;
	}
	if( memo[y][x][yoko][tate] != -1 ){
		return memo[y][x][yoko][tate];
	}
	
	if( g[y][x] == '.' ){
		if( yoko && tate / pow3[W-1] % 3 ) return 0;
		return dfs(x+1,y,yoko,(tate * 3 + tate / pow3[W-1] % 3 ) % pow3[W]);
	}else{
		int need = g[y][x] - '0' - yoko - tate / pow3[W-1] % 3;
		int ans = 0;
		for(int i = 0 ; i <= 2 ; i++){
			for(int j = 0 ; j <= 2 ; j++){
				if( i + j == need ){
					ans += dfs(x+1,y,i,(tate * 3 + j) % pow3[W]);
					if( ans > 100000007 ) ans -= 100000007;
				}
			}
		}
		return memo[y][x][yoko][tate] = ans;
	}
}
int main(){
	pow3[0] = 1;
	for(int i = 1 ; i < 20 ; i++)
		pow3[i] = pow3[i-1] * 3;
	cin >> H >> W;
	for(int i = 0 ; i < H ; i++)
		for(int j = 0 ; j < W ; j++)
			cin >> g[i][j];
	memset(memo,-1,sizeof(memo));
	cout << dfs(0,0,0,0) << endl;
}