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<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;
 
const int mod = (int)1e8 + 7;
int h, w, pw[11];
char in[12][12];
int dp[2][11][3][60000];
 
int main(){
  pw[0] = 1;
  rep(i, 10) pw[i + 1] = pw[i] * 3;
  
  cin >> h >> w;
  rep(i, h) cin >> in[i];
  
  int cur = 0, next = 1;
  dp[0][0][0][0] = 1;
  
  rep(i, h){
    memset(dp[next], 0, sizeof(dp[next]));
    rep(j, w){
      rep(l, 3) rep(u, pw[w]) if(dp[cur][j][l][u]){
	int tu = u / pw[j] % 3;
	
	if(in[i][j] == '.'){
	  if(tu && l) continue;
	  (dp[cur][j + 1][l][u] += dp[cur][j][l][u]) %= mod;
	  continue;
	}
	int rest = in[i][j] - '0' - tu - l;
	rep(nl, 3){
	  int nu = rest - nl;
	  if(nu < 0 || nu > 2) continue;
 	  
	  (dp[cur][j + 1][nl][u + pw[j] * (nu - tu)] += dp[cur][j][l][u]) %= mod;
	}
      }
    }
    rep(u, pw[w]) dp[next][0][0][u] = dp[cur][w][0][u];
    swap(cur, next);
  }
  cout << dp[cur][0][0][0] << endl;
  
  return 0;
}