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 JAVA):

Solution:
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
//rankaleeさんのをこぴぺさせていただきました...

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	long MOD = (int)(1e8)+7;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt();
		int[] pow = new int[w+1];
		pow[0] = 1;
		for(int i=1;i<=w;i++) pow[i] = (int)(pow[i-1]*3%MOD);
		long[][][] dp = new long[2][3][pow[w]];
		dp[0][0][0] = 1;
		String[] map = new String[h];
		for(int i=0;i<h;i++) map[i] = sc.next();
		int p = 1;
		for(int i=0;i<h;i++) for(int j=0;j<w;j++) {
			for(long[] a: dp[p]) fill(a, 0);
			for(int k=0;k<3;k++) for(int u=0;u<pow[w];u++) if(dp[1-p][k][u] != 0){
				
				int tu = u/pow[j]%3;
//				debug(p, k , u, i, j, tu);
				if(map[i].charAt(j) == '.') {
					if(tu * k > 0) continue;
					if(k == 0 || j < w-1) dp[p][k][u] = ( dp[p][k][u] + dp[1-p][k][u] ) % MOD;
					continue;
				}
				int r = map[i].charAt(j) - '0' - tu - k;
				for(int nk=0;nk<3;nk++) {
					int nu = r - nk;
					if(nu < 0 || nu > 2) continue;
					if(nk == 0 || j < w-1 ) {
						dp[p][nk][u + pow[j]*(nu-tu)] = (dp[p][nk][u + pow[j]*(nu-tu)] + dp[1-p][k][u]) % MOD;
					}
				}
			}
//			debug(dp[p]);
			p = 1-p;
		}
		System.out.println(dp[1-p][0][0]);
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}