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<stdio.h>
#include<algorithm>
using namespace std;
char str[20][20];
int pow3[13];
int mod=100000007;
int dp[12][12][60000][3];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%s",str[i]);
	}
	pow3[0]=1;
	for(int i=1;i<13;i++)pow3[i]=pow3[i-1]*3;
	dp[0][0][0][0]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			for(int k=0;k<pow3[b];k++){
				for(int l=0;l<3;l++){
					if(!dp[i][j][k][l])continue;
			//		printf("%d %d %d %d: %d\n",i,j,k,l,dp[i][j][k][l]);
					if(str[i][j]=='.'){
						if(k%3&&l)continue;
						dp[i][j+1][k/3+pow3[b-1]*(k%3)][l]=(dp[i][j+1][k/3+pow3[b-1]*(k%3)][l]+dp[i][j][k][l])%mod;
					}else{
						int rem=str[i][j]-'0'-l-k%3;
						if(rem<0)continue;
						for(int m=0;m<3;m++)for(int n=0;n<3;n++){
							if(rem==m+n){
								dp[i][j+1][k/3+pow3[b-1]*m][n]=(dp[i][j+1][k/3+pow3[b-1]*m][n]+dp[i][j][k][l])%mod;
							}
						}
					}
				}
			}
		}
		for(int j=0;j<pow3[b];j++){
			dp[i+1][0][j][0]=dp[i][b][j][0];
		}
	}
	printf("%d\n",dp[a][0][0][0]);
}