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>
#define M 100000007
using namespace std;

int r,c;
int dp[2][10][3][100000]; //dp[r][c][左からn本][上からn本]
int g[20][20];
char z;
int po3[21];

int main(){
  cin >> r >> c;

  po3[0] = 1;
  for(int i=0;i<c;i++)po3[i+1] = po3[i]*3;

  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++){
      cin >> z;
      if(z=='.')g[i][j] = 0;
      else g[i][j] = z-'0';
    }

  for(int i=0;i<c;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<po3[c];k++)dp[0][i][j][k] = 0;
  dp[0][0][0][0] = 1;

  for(int i=0;i<r;i++){
    int id = i&1, nxt = 1-id;

    for(int j=0;j<c;j++)
      for(int k=0;k<3;k++)
	for(int l=0;l<po3[c];l++)dp[nxt][j][k][l] = 0;

    for(int j=0;j<c-1;j++){
      if(!g[i][j]){
	for(int k=0;k<3;k++){
	  for(int l=0;l<po3[c];l++){
	    int m = (l/po3[j])%3;
	    if(m && k)continue;
	    dp[id][j+1][k][l] += dp[id][j][k][l];
	    dp[id][j+1][k][l] %= M;
	  }
	}
      }else{
	for(int k=0;k<3;k++){
	  for(int l=0;l<po3[c];l++){
	    int m = (l/po3[j])%3;
	    int n = g[i][j] - m - k;
	    
	    if(n<0 || n>4)continue;
	    for(int x=0;x<3;x++){
	      if(n-x<0 || n-x>2)continue;
	      int w = l - m*po3[j] + (n-x)*po3[j];
	      dp[id][j+1][x][w] += dp[id][j][k][l];
	      dp[id][j+1][x][w] %= M;
	    }
	  }
	}
      }
    }

    if(!g[i][c-1]){
      for(int l=0;l<po3[c];l++){
	dp[nxt][0][0][l] += dp[id][c-1][0][l];
	dp[nxt][0][0][l] %= M;
      }
    }else{
      for(int k=0;k<3;k++){
	for(int l=0;l<po3[c];l++){
	  int m = (l/po3[c-1])%3;
	  int n = g[i][c-1] - m - k;
	  if(n<0 || n>2)continue;
	  int w = l - m*po3[c-1] + n*po3[c-1];
	  dp[nxt][0][0][w] += dp[id][c-1][k][l];
	  dp[nxt][0][0][w] %= M;
	}
      }
    }
  }

  cout << dp[r&1][0][0][0] << endl;
}