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<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

const int mod = 100000007;
int h,w,pow3[13];
int dp[11*11][180000];
char field[12][12];

#define get(bit,x) ((bit)/pow3[(x)]%3)
#define set(bit,x,value) ((bit)-(((bit)/pow3[x]%3)*pow3[x])+(value*pow3[x]))
#define fix(bit,width) ((bit)*3%pow3[width])

void compute(){
  bool starter = true;  
  rep(y,h){
    rep(x,w){
      if( starter && field[y][x] == '.' ) continue;
      if( starter ) { starter = false; ++dp[x+y*w][0]; }

      bool update = false;
      rep(bitmask3,pow3[w+1]){
	if( dp[x+y*w][bitmask3] == 0 ) continue;
	update = true;
	int left = get(bitmask3,x);
	int top  = get(bitmask3,x+1);
	if( field[y][x] == '.' ) {
	  if( left && top ) continue;
	  if( left && x == w-1 ) continue;
	  if( top && y == h-1 ) continue;
	  int nbitmask = bitmask3;
	  nbitmask = set(nbitmask,x,top);
	  nbitmask = set(nbitmask,x+1,left);
	  if( x == w-1 ) nbitmask = fix(nbitmask,w+1);
	  ( dp[x+y*w+1][nbitmask] += dp[x+y*w][bitmask3] ) %= mod;
	  continue;
	}

	int remain = field[y][x] - '0' - left - top;
	if( remain < 0 || remain > 4 ) continue;
	rep(next_bottom,3){
	  int next_right = remain - next_bottom;
	  if( next_right < 0 || next_right > 2 ) continue;
	  int nbitmask = bitmask3;
	  if( next_right && x == w-1 ) continue;
	  if( next_bottom && y == h-1 ) continue;
	  nbitmask = set(nbitmask,x,next_bottom);
	  nbitmask = set(nbitmask,x+1,next_right);
	  if( x == w-1 ) nbitmask = fix(nbitmask,w+1);
	  ( dp[x+y*w+1][nbitmask] += dp[x+y*w][bitmask3] ) %= mod;
	}
      }
    }
  }
  int sum = 0;
  rep(i,pow3[w+1]) ( sum += dp[h*w][i] ) %= mod;
  assert( sum >= 0 );
  cout << sum << endl;
}

int main(){
  pow3[0] = 1;
  REP(i,1,13) pow3[i] = pow3[i-1] * 3;

  cin >> h >> w;
  rep(i,h) scanf(" %s",&field[i]);
  compute();
  return 0;
}