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 <cmath>
using namespace std;
 
typedef long long lli;

const int MAX = 59049; // 3 ^ 10
const lli MOD = 100000007;
 
int h,w,v[10][10];
int pow3[12];
 
int getbit(int bit, int pos){
  bit /= pow3[pos];
  return bit %= 3;
}
 
int setbit(int bit, int num, int pos){
  return bit - getbit(bit,pos) * pow3[pos] + num * pow3[pos];
}

int shiftleft(int bit){
  bit *= 3;
  return setbit(bit, 0, w);
}
 
void makepow(){
  pow3[0] = 1;
  for(int i=1;i<12;i++) pow3[i] = pow3[i-1] * 3;
}

void solve(){
  lli dp[2][3][MAX];

  fill(dp[0][0],dp[2][0],0);
  dp[0][0][0] = 1;
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<3;k++){
        for(int l=0;l<pow3[w];l++){
          if(dp[0][k][l] == 0) continue;
          int up = getbit(l, w-1);
          int rem = v[i][j] - up - k;
          if(!v[i][j]) {
            if(k > 0 && up > 0) continue;
            rem = up + k;
          }
          for(int ri=0;ri<=min(2,rem);ri++){
            int bo = rem - ri;
            int next = setbit(shiftleft(l), bo, 0);
            if(bo > 2) continue;
            if(!v[i][j] && (up > 0 && ri > 0 || k > 0 && bo > 0)) continue;
            if(i < h - 1 && v[i+1][j] && bo > v[i+1][j] || i == h - 1 && bo > 0) continue;
            if(j < w - 1 && v[i][j+1] && ri > v[i][j+1] || j == w - 1 && ri > 0) continue;
            //cout << i << ' ' << j << ' ' << ri << ' ' << bo << endl;
            dp[1][ri][next] = (dp[1][ri][next] + dp[0][k][l]) % MOD;
          }
        }
      }
      for(int k=0;k<3;k++){
        for(int l=0;l<pow3[w];l++){
          dp[0][k][l] = dp[1][k][l];
          dp[1][k][l] = 0;
        }
      }
    }
  }

  int ans = 0;
  for(int i=0;i<3;i++)
    for(int j=0;j<pow3[w];j++)
      ans += dp[0][i][j];      
  cout << ans << endl;
}
 
int main(){
  makepow();

  while(cin >> h >> w){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        char c;
        cin >> c;
        if(c == '.') v[i][j] = 0;
        else v[i][j] = c - '0';
      }
    }  
    solve();
  }
}