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>

using namespace std;
const int MOD = 100000007;

int dp[11][10][3][60000] = { { { { 0 } } } };

inline int fall(int bits, int i){
	return (bits >> (i * 2)) & 0x03;
}

int main(){
	int r, c;
	cin >> r >> c;
	vector<string> field(r);
	for(int i = 0; i < r; ++i){ cin >> field[i]; }
	vector<int> state_dic(1 << (c * 2));
	vector<int> state_rdic(1 << (c * 2));
	int state_count = 0;
	for(int i = 0; i < (1 << (c * 2)); ++i){
		if(i & (i >> 1) & 0x55555555){ continue; }
		state_dic[i] = state_count;
		state_rdic[state_count] = i;
		++state_count;
	}
	dp[0][0][0][0] = 1;
	for(int i = 0; i < r; ++i){
		for(int j = 0; j + 1 < c; ++j){
			int v = field[i][j] - '0';
			if(field[i][j] == '.'){ v = -1; }
			for(int k = 0; k <= 2; ++k){
				for(int s = 0; s < state_count; ++s){
					int cur = dp[i][j][k][s];
					if(cur == 0){ continue; }
					int raw_s = state_rdic[s];
					int f = fall(raw_s, j);
					if(v < 0){
						if(k == 0 || f == 0){
							dp[i][j + 1][k][s] =
								(dp[i][j + 1][k][s] + cur) % MOD;
						}
					}else{
						int masked = raw_s & ~(3 << (j * 2));
						int cv = v - f - k;
						if(cv < 0){ continue; }
						for(int a = 0; a <= 2; ++a){
							for(int b = 0; b <= 2; ++b){
								if(a + b != cv){ continue; }
								int c = masked | (a << (j * 2));
								int cc = state_dic[c];
								dp[i][j + 1][b][cc] =
									(dp[i][j + 1][b][cc] + cur) % MOD;
							}
						}
					}
				}
			}
		}
		{
			int j = c - 1;
			int v = field[i][j] - '0';
			if(field[i][j] == '.'){ v = -1; }
			for(int k = 0; k <= 2; ++k){
				if(v < 0 && k >= 1){ continue; }
				for(int s = 0; s < state_count; ++s){
					int cur = dp[i][j][k][s];
					if(cur == 0){ continue; }
					int raw_s = state_rdic[s];
					int f = fall(raw_s, j);
					if(v < 0){
						if(k == 0 || f == 0){
							dp[i + 1][0][0][s] =
								(dp[i + 1][0][0][s] + cur) % MOD;
						}
					}else{
						int masked = raw_s & ~(3 << (j * 2));
						int cv = v - f - k;
						if(cv < 0 || cv > 2){ continue; }
						int c = masked | (cv << (j * 2));
						int cc = state_dic[c];
						dp[i + 1][0][0][cc] =
							(dp[i + 1][0][0][cc] + cur) % MOD;
					}
				}
			}
		}
	}
	cout << dp[r][0][0][0] << endl;
	return 0;
}