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 <numeric>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1000 * 1000 * 100 + 7;


int R, C;
int memo[10][10][200000];
char field[10][10];

inline vector<int> decode(int mask){
  vector<int> v(C + 1);
  REP(i, C + 1){
    v[i] = mask % 3;
    mask /= 3;
  }
  return v;
}

inline int encode(const vector<int> &v){
  int mask = 0;
  int N = 1;
  REP(i, C + 1){
    mask += v[i] * N;
    N *= 3;
  }
  return mask;
}

int calc(int r, int c, int mask){
  if(r == R) return mask == 0;
  if(c == C) return mask % 3 == 0 ? calc(r + 1, 0, mask) : 0;
  
  if(memo[r][c][mask] != -1) return memo[r][c][mask];
  int &res = memo[r][c][mask] = 0;
  vector<int> v = decode(mask);
  int left = v[0];
  int down = v[c+1];
  
  if(field[r][c] == 0){
    if(left == 0 || down == 0){
      res = calc(r, c + 1, mask);
    }
  }else{
    int rest = field[r][c] - left - down;
    REP(nleft, 3){
      int ndown = rest - nleft;
      if(0 <= ndown && ndown <= 2){
        v[0] = nleft;
        v[c+1] = ndown;
        res += calc(r, c + 1, encode(v));
        res %= mod;
      }
    }
  }
  return res ;
}
 

int main(){
  cin >> R >> C;
  REP(i, R)REP(j, C){
    cin >> field[i][j];
    field[i][j] = isdigit(field[i][j]) ? field[i][j] - '0' : 0;
  }
  memset(memo, -1, sizeof(memo));
  cout << calc(0, 0, 0) << endl;
  
  return 0;
}