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 <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int MOD = 100000007;

int main()
{
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for(int i=0; i<h; ++i)
        cin >> s[i];

    map<string, int> curr;
    curr[string(w, '0')] = 1;

    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            map<string, int> next;

            if(s[y][x] == '.'){
                for(map<string, int>::iterator it=curr.begin(); it!=curr.end(); ++it){
                    string t = it->first;
                    rotate(t.begin(), t.begin()+1, t.end());
                    (next[t] += it->second) %= MOD;
                }
            }else{
                for(map<string, int>::iterator it=curr.begin(); it!=curr.end(); ++it){
                    string t = it->first;
                    if(t[0] > '2' || t[0] > s[y][x])
                        continue;

                    t = t.substr(1) + (char)(s[y][x] - (t[0] - '0'));
                    if(*max_element(t.begin(), t.end()-1) <= '2')
                        (next[t] += it->second) %= MOD;

                    bool ng = false;
                    int k = x - 1;
                    while(k >= 0 && s[y][k] == '.'){
                        if(t[k+w-x-1] != '0')
                            ng = true;
                        -- k;
                    }

                    if(k >= 0 && !ng){
                        k += w - x - 1;
                        if(t[w-1] != '0' && t[k] != '0'){
                            -- t[w-1];
                            -- t[k];
                            if(*max_element(t.begin(), t.end()-1) <= '2')
                                (next[t] += it->second) %= MOD;
                        }
                        if(t[w-1] != '0' && t[k] != '0'){
                            -- t[w-1];
                            -- t[k];
                            if(*max_element(t.begin(), t.end()-1) <= '2')
                                (next[t] += it->second) %= MOD;
                        }
                    }
                }
            }

            curr.swap(next);
        }
    }

    cout << curr[string(w, '0')] << endl;

    return 0;
}