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 <cstring>

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define MEMSET(v, s) memset(v, s, sizeof(v))

using namespace std;

vector<string> v;
const int MOD = 1e8 + 7;
int dp[10][10][60000][3];
int R, C;
int thr[11];

inline int get(int x, int pos){
	return x / thr[pos] % 3;
}

inline int ins(int x, int pos, int val){
	return x + (val - get(x, pos))*thr[pos];
}

int rec(int r, int c, int x, int left){
	if (r == R) return !x;
	if (c == C) return left?0:rec(r + 1, 0, x, 0);

	int &res = dp[r][c][x][left];
	if (res >= 0) return res;

	res = 0;
	if (v[r][c] == '.'){
		if (!(get(x, c) && left)) res = rec(r, c + 1, x, left);
	}
	else{
		int rest = v[r][c] - '0';
		rest -= get(x, c) + left;
		rep(right, 3){
			rep(down, 3){
				if (right + down != rest) continue;
				res += rec(r, c + 1, ins(x, c, down), right);
				res %= MOD;
			}
		}
	}

	return res;
}

int main(){
	thr[0] = 1;
	FOR(i, 1, 11) thr[i] = thr[i - 1] * 3;

	cin >> R >> C;
	v.resize(R);
	rep(i, R) cin >> v[i];

	MEMSET(dp, -1);
	cout << rec(0, 0, 0, 0) << endl;

	return 0;
}