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 <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int W, H, a[11][11], rt[10][10], dn[10][10], dp[2][1 << 20], y, z;
vector<int> b;

void f(int x, int p) {
    int rx = rt[y][x];
    int mn = min({ 2, a[y][x], a[y][rx] });
    mn = p >> x * 2 + 2 & ~(-1 << (rx - x - 1) * 2) ? 0 : mn;
    for (int i = a[y][x] - min({ 2, a[y][x], a[dn[y][x]][x] }); i <= mn; ++i) {
        int q = p & ~(3 << x * 2) | a[y][x] - i << x * 2;
        if (rx == W) {
            dp[y & 1][q] = (dp[y & 1][q] + z) % 100000007;
        } else {
            a[y][rx] -= i;
            f(rx, q);
            a[y][rx] += i;
        }
    }
}

void g(int x, int p) {
    if (x) {
        for (int i = 0; i < 3; ++i)
            g(x - 1, p << 2 | i);
    } else {
        b.emplace_back(p);
    }
}

int main() {
    cin >> H >> W;
    int A[11][11]{};
    for (int y = 0; y < H; ++y) {
        char s[11];
        cin >> s;
        bool none = true;
        for (int x = 0; x < W; ++x) {
            if (s[x] != '.') {
                A[y][x] = s[x] - '0';
                none = false;
            }
        }
        if (none) {
            --H;
            --y;
        }
    }
    for (int y = 0; y < H; ++y) {
        for (int x = 0; x < W; ++x) {
            if (A[y][x]) {
                int i = x + 1;
                for (; i < W && !A[y][i]; ++i);
                rt[y][x] = i;
                for (i = y + 1; i < H && !A[i][x]; ++i);
                dn[y][x] = i;
            }
        }
    }
    memcpy(a, A, sizeof a);
    g(W, 0);
    dp[1][0] = 1;
    for (y = 0; y < H; ++y) {
        memset(dp[y & 1], 0, sizeof dp[y & 1]);
        int x = 0;
        for (; !a[y][x]; ++x);
        for (int p : b) {
            z = dp[y + 1 & 1][p];
            if (z) {
                for (int i = x; i < W; i = rt[y][i])
                    a[y][i] -= p >> i * 2 & 3;
                f(x, p);
                memcpy(a[y], A[y], sizeof a[y]);
            }
        }
    }
    cout << dp[H + 1 & 1][0] << endl;
    return 0;
}