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<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const double inf=1e8;
vector<map<vi,int> >dp;
vi tmp;
string tms;
int r,n,m,c,MOD=100000007;
//map<vi,int>q;
vi q;
vi f(int a){
	vi out(m);
	rep(i,m){
		out[m-i-1]=a%3;
		a/=3;
	}
	return out;
}
int ff(vi a){
	int t=0;
	rep(i,m){
		t*=3;
		t+=a[i];
	}
	return t;
}
void dfs(int a){
	if(a==m){
		if(r)return;
		(q[ff(tmp)]+=c)%=MOD;	
		return;
	}
	if(tms[a]=='.'){
		if(r&&tmp[a])return;
		dfs(a+1);
		return;
	}
	int w=r;
	if(tms[a]-'0'<w)return;
	tms[a]-=w;
	rep(i,min(3,tms[a]-'0'+1))if(tms[a]-'0'-i<3){
		tmp[a]=i;
		r=tms[a]-'0'-i;
		dfs(a+1);
		tmp[a]=0;
	}
	
	tms[a]+=w;
}
int main(){
	cin>>n>>m;
	vs in(n);
	rep(i,n)cin>>in[i];
//	map<vi,int>dp;
	int N=pow(3,m);
	vi dp(N);
	dp[0]=1;
	rep(i,n){
		q=vi(N);
		rep(z,N)if(dp[z]){
	//		for(map<vi,int>::iterator it=dp.begin();it!=dp.end();it++){
			tmp=f(z);
			tms=in[i];
			bool h=true;
			rep(j,m)if(tms[j]!='.'){
				if(tmp[j]>tms[j]-'0')h=false;
				else{
					tms[j]-=tmp[j];
					tmp[j]=0;
				}
			}
			if(!h)continue;
			r=0;
			c=dp[z];
			dfs(0);
		}
		dp=q;
	}
	cout<<dp[0]<<endl;
}