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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <fstream>
#include <cassert>
#include <ctime>
#include <list>
#include <numeric>
#include <iomanip>


using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#ifndef M_PI
const double M_PI=acos(-1);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
int dx[]={0,1,0,-1,1,1,-1,-1},dy[]={1,0,-1,0,1,-1,1,-1};

char in[10][10];

ll MOD = 100000007;
ll dp[2][1<<22];

vector<int> state;
int r,c;
void dfs(int dep,int cu){
  if(dep==c+1){
    state.pb(cu);
    return;
  }

  rep(i,3)
    dfs(dep+1,cu*4+i);
}

int main(){

  cin >> r >> c;
  rep(i,r)rep(j,c){
    cin >> in[i][j];
    if(isdigit(in[i][j])) in[i][j]-='0';
    else in[i][j]=0;
  }

  dfs(0,0);
  
  int p=0;
  dp[0][0] = 1;
  rep(i,r)rep(j,c){
    //memset(dp[!p],0,sizoef(dp[!p]));
    FOR(it,state) dp[!p][*it]=0;
    p=!p;
    FOR(it,state){
      //cout << i << ' ' << j << ' ' << ' ' << *it << ' ' << dp[!p][*it] << endl;
      int up=(*it>>(2*c))&3;
      int left=(*it)&3;
      int ed=in[i][j];
      int cst = *it;
      if(j==0 && left) continue;
      if(ed && up+left>ed) continue;
      if(ed==0){
        if(up && left) continue;
        cst <<= 2;
        cst &= (1<<(c+1)*2)-1;
        cst &= ~15;        
        if(up) cst |= up<<2;
        else cst |= left;
        dp[p][cst] =(dp[p][cst]+dp[!p][*it])%MOD;
      }else{

        ed -= up+left;
        if(ed<0) continue;
        cst <<= 2;
        cst &= (1<<(c+1)*2)-1;
        cst &= ~15;
        for(int nleft=0;nleft<=min(2,ed);++nleft){
          if(ed-nleft>2) continue;
          int nst=cst;
          nst |= nleft|((ed-nleft)<<2);
          dp[p][nst] =(dp[p][nst]+dp[!p][*it])%MOD;
        }
      }
      
    }
  }

  cout << dp[p][0] << endl;
}