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>
using namespace std;
using Int = long long;
Int h,w;
string s[100];
const Int MOD = 1e8+7;
Int dp[11][100000];
Int po[20];
Int dfs(Int y,Int b);
Int dfs2(Int y,Int x,vector<Int> &v);

const Int DBG = 0;
Int dfs(Int y,Int b){
  if(DBG) cout<<y<<":"<<b<<endl;
  if(y==h) return b==0;
  Int &res=dp[y][b];
  if(~res) return res;
  res=0;
  vector<Int> v(w,0);
  for(Int i=0;i<w;i++){
    v[i]=-((b/po[i])%3);
    if(s[y][i]=='.') continue;
    v[i]+=s[y][i]-'0';
    if(v[i]<0) return res;
  }
  if(DBG){
    for(Int i=0;i<w;i++) cout<<v[i]<<":";
    cout<<endl;
  }
  res+=dfs2(y,0,v);
  res%=MOD;
  if(DBG) cout<<y<<":"<<b<<":"<<res<<endl;
  return res;
}
Int calc(vector<Int> &v){
  Int b=0;
  for(Int i=w-1;i>=0;i--){
    if(v[i]>0||-v[i]>2) return -1;
    b=b*3+(-v[i]);
  }
  return b;
}
Int dfs2(Int y,Int x,vector<Int> &v){
  //cout<<y<<"*"<<x<<endl;
  while(x<w&&!isdigit(s[y][x])) x++;
  if(x==w){
    Int b=calc(v);
    if(~b) return dfs(y+1,b);
    return 0;
  }
  Int px=x++,flg=0;
  while(x<w&&!isdigit(s[y][x])){
    flg|=(v[x]<0); 
    x++;
  }
  if(x==w){
    v[px]*=-1;
    Int res=dfs2(y,x,v);
    v[px]*=-1;
    return res;
  }
  Int res=0;
  Int pv=v[px];
  for(Int i=0;i<=pv;i++){
    if(i>=3||pv-i>=3) continue;
    if(flg && i!=pv) continue;
    v[x]-=pv-i;
    v[px]=-i;
    res+=dfs2(y,x,v);
    res%=MOD;
    v[x]+=pv-i;
    v[px]=pv;
  }
  return res;
}


signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin>>h>>w;
  for(Int i=0;i<h;i++) cin>>s[i];
  po[0]=1;
  for(Int i=1;i<20;i++) po[i]=po[i-1]*3;
  memset(dp,-1,sizeof(dp));
  cout<<dfs(0,0)<<endl;
  return 0;
}