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 <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#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()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int a[10][10];
int dp[2][177147];

int pown[20];

int get(int S, int i) {
  return S/pown[i]%pown[1];
}
inline int change(int S, int i, int x) {
  S -= get(S,i)*pown[i];
  S += x*pown[i];
  return S;
}
void init(int n, int m) {
  pown[0] = 1;
  REP(i,m) pown[i+1] = pown[i]*n;
}

int mod = 1e8 + 7;
int pre[10][10];

int main() {
  init(3,15);
  
  int h, w;
  while(cin >> h >> w) {

    REP(i,h)REP(j,w) {
      char c;
      cin >> c;
      a[i][j] = (c=='.'?0:c-'0');
    }

    REP(i,h) {
      int p = -1;
      REP(j,w) {
        pre[i][j] = p;
        if (a[i][j]) p = j;
      }
    }
    
    memset(dp,0,sizeof(dp));

    int *cur = dp[0];
    int *nxt = dp[1];

    cur[0] = 1;

    REP(y,h) {
      REP(x,w) {
        REP(S,pown[w+1]) nxt[S] = 0;
        REP(S,pown[w+1]) {
          if (x == 0 && get(S,w)) continue; // 右端に飛び出てる
          if (a[y][x] == 0) {
            nxt[S] = cur[S];
          } else {
            int rest = a[y][x] - get(S,w) - get(S,x);
            if (get(S,w)) {
              bool dame = 0;
              for (int i=pre[y][x]+1; i<x; ++i)
                if (get(S,i)) dame = 1;
              if (dame) continue;
            }
            for (int yoko=0; yoko<=min(2,rest); ++yoko) {
              int tate = rest - yoko;
              if (tate > 2) continue;
              int T = change(S,w,yoko);
              T = change(T,x,tate);
              nxt[T] = (nxt[T] + cur[S]) % mod;
            }
          }
        }
        swap(cur,nxt);
      }
    }
    cout << cur[0] << endl;
  }
}