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;

const int MAX = 59049; // 3 ^ 10
const int MOD = 100000007;

int h,w,v[10][10],memo[10][MAX];

int getbit(int bit, int a){
  for(int i=0;i<a;i++) bit /= 3;
  return bit %= 3;
}

int setbit(int bit, int a, int b){
  return bit + a * (int)pow(3.0,b);
}

void dfs(int y, int x, int bit, int next, int yoko, int prev){
  //cout << "y = " << y << ", x = " << x << ", next = " << next << ", yoko = " << yoko << endl; 

  int gbit = getbit(bit,x);
  int cnt = yoko + gbit;

  if(x >= w - 1){
    if(v[y][x] - cnt >= 0 && v[y][x] - cnt <= 2){
      int nexta = setbit(next,v[y][x]-cnt,x);
      memo[y][nexta] = (memo[y][nexta] + prev) % MOD;
    }else if(v[y][x] == 0 && gbit && yoko == 0){
      int nexta = setbit(next,gbit,x);
      memo[y][nexta] = (memo[y][nexta] + prev) % MOD;
    }
    return;
  }

  if(v[y][x] == 0){
    if(yoko == 0 || gbit == 0) dfs(y,x+1,bit,setbit(next,gbit,x),yoko,prev);
    return;
  }
 
  for(int i=0;i<=2;i++){
    for(int j=0;j<=2;j++){
      if(cnt + i + j == v[y][x]){
        dfs(y, x+1, bit, setbit(next,i,x), j, prev);
      }
    }
  }
}

int main(){
  while(cin >> h >> w){
    int pos = -1;
    fill(memo[0],memo[10],0);
    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';
      }
    }
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(v[i][j] > 0){
          dfs(i, j, 0, 0, 0, 1);
          pos = i;
          break;
        }
      }
      if(pos >= 0) break;
    }
    
    for(int i=pos+1;i<h;i++)
      for(int j=0;j<MAX;j++)
        if(memo[i-1][j] > 0)
          dfs(i, 0, j, 0, 0, memo[i-1][j]);
    
    cout << memo[h-1][0] << endl;
  }
}