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<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int M=100000007;

int h,w;
char B[10][11];

int encode(const vector<int> &S){
	int res=0;
	rep(i,w+1) res=res*3+S[i];
	return res;
}

int dp[10][10][177147];
int dfs(int i,int j,vector<int> S){
	if(i==h){
		bool ok=true;
		rep(k,w+1) if(S[k]>0) ok=false;
		return ok?1:0;
	}

	if(j==w){
		if(S[w]>0) return 0;
		else       return dfs(i+1,0,S);
	}

	int E=encode(S);
	if(dp[i][j][E]!=-1) return dp[i][j][E];

	int res=0;
	if(B[i][j]=='.'){
		if(S[w]==0){
			res+=dfs(i,j+1,S);
			res%=M;
		}
		else if(S[j]==0){
			res+=dfs(i,j+1,S);
			res%=M;
		}
	}
	else{
		int num=B[i][j]-'0';
		if(S[w]+S[j]<=num){
			num-=S[w]+S[j];
			if(num<=4){
				rep(k,num+1) if(k<=2 && num-k<=2) {
					S[j]=k;
					S[w]=num-k;
					res+=dfs(i,j+1,S);
					res%=M;
				}
			}
		}
	}

	return dp[i][j][E]=res;
}

int main(){
	scanf("%d%d",&h,&w);
	rep(i,h) scanf("%s",B[i]);

	memset(dp,-1,sizeof dp);
	printf("%d\n",dfs(0,0,vector<int>(w+1,0)));

	return 0;
}