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 <algorithm>
#include <cstring>

using namespace std;

const int M = 100000007;

int dp[2][3][59049], h, w, d[11];
char m[10][10];

int main(){
  d[0] = 1;
  for(int i=0;i<10;i++) d[i+1] = d[i] * 3;
  cin >> h >> w;
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> m[i][j];
  int c = 0;
  dp[0][0][0] = 1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      memset(dp[1-c], 0, sizeof(dp[1-c]));
      for(int k=0;k<3;k++){
        for(int l=0;l<d[w];l++){
          if(dp[c][k][l]){
            int s = l / d[j] % 3;
            if(m[i][j] == '.'){
              if(k && s) continue;
              if(k == 0 || j < w - 1) (dp[1-c][k][l] += dp[c][k][l]) %= M;
            }else{
              for(int u=0;u<3;u++){
                int t = m[i][j] - '0' - k - s - u;
                if(t < 0 || t > 2) continue;
                if(u == 0 || j < w - 1) (dp[1-c][u][l+d[j]*(t-s)] += dp[c][k][l]) %= M;
              }
            }
          }
        }
      }
      c = 1 - c;
    }
  }
  cout << dp[c][0][0] << endl;
}