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 <cassert>
#include <cstdio>
#include <cstring>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <queue>
#include <set>
using namespace std;

vector<string> g;
int h, w;

int dp[10][10][3][59049 + 10];
const int mod = 100000007;

void decode(int val, int *ret){
  REP(i,w){
    ret[i] = val % 3;
    val /= 3;
  }
}

int encode(int *a){
  int ret = 0;
  REP(i,w){
    ret *= 3;
    ret += a[w - 1 - i];
  }
  return ret;
}

bool valid(int a, int b, int c, int d){
  int sum = a + b + c + d;
  int mx = max(max(a,b),max(c,d));
  return mx <= sum - mx;
}

int solve(int y, int x, int prev, int val){
  assert(val < 59049 + 10);
  if(y == h && x == 0){
    return val == 0 ? 1 : 0;
  }
  if(x == w){
    if(prev != 0) return 0;
    return solve(y + 1, 0, 0, val);
  }

  if(dp[y][x][prev][val] != -1)
    return dp[y][x][prev][val];

  int a[w + 1]; decode(val, a);
  int in = prev + a[0];

  int ret = 0;

  if(g[y][x] == '.'){
    /*
    REP(migi, 3) REP(sita, 3){
      if((migi + sita + in) % 2 != 0) continue;
      if(!valid(migi, sita, a[0], prev)) continue;

      if(y == h - 1 && sita != 0) continue;
      if(x == w - 1 && migi != 0) continue;

      printf("%d, %d (ue:%d, migi:%d sita:%d, hidari:%d)\n", y, x, a[0], migi, sita, prev);

      a[w] = sita;
      ret += solve(y, x + 1, migi, encode(a + 1));
      ret %= mod;
    }
    */
    if(prev > 0 && a[0] > 0) return 0;
    if(prev > 0){
      if(x != w - 1){
	a[w] = 0;
	ret += solve(y, x + 1, prev, encode(a + 1));
      }
    }else if(a[0] > 0){
      if(y != h - 1){
	a[w] = a[0];
	ret += solve(y, x + 1, 0, encode(a + 1));
      }
    }else{
      a[w] = 0;
      ret += solve(y, x + 1, 0, encode(a + 1));
    }
  }else{
    const int expected = g[y][x] - '0';

    REP(migi, 3){
      const int sita = expected - in - migi;

      if(y == h - 1 && sita != 0) continue;
      if(x == w - 1 && migi != 0) continue;

      if(0 <= sita && sita <= 2){
	// printf("%d, %d (ue:%d, migi:%d sita:%d, hidari:%d)\n", y, x, a[0], migi, sita, prev);

	a[w] = sita;
	ret += solve(y, x + 1, migi, encode(a + 1));
	ret %= mod;
      }
    }
  }

  return dp[y][x][prev][val] = ret;
}


int main(){
  cin >> h >> w;
  g = vector<string>(h);
  REP(i,h) cin >> g[i];

  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, 0, 0) << endl;

  return 0;
}