import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
import std.ascii;
 
void main() {
    int r, c; readf("%d %d\n", &r, &c);
    string[] F = new string[r];
    foreach (ref L; F) L = readln.chomp;

    const INF = int.max / 2;
    const C = 100_000_007;

    int dfs(int y, int x, int[] u) {
        if (y == r) return u.all!"a == 0";
        if (x == c) return dfs(y + 1, 0, u);
        //writeln([y, x], " ", u);
        if (F[y][x] == '.') return dfs(y, x + 1, u);
        assert(F[y][x].isDigit);
        int v = F[y][x] - '0';
        //writeln(v, " ", u[x]);
        v -= u[x];
        u[x] = 0;
        if (v < 0 || 4 < v) return 0;
        int ret = 0;
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j <= 2; j++) {
                if (i + j != v) continue;
                int[] u1 = u.dup;
                if (j != 0) {
                    foreach (k; x + 1 .. c) {
                        if (F[y][k].isDigit) {
                            u1[k] += j;
                            goto found;
                        }
                        if (u[k]) goto not_found;
                    }
                    not_found: continue;
                }
                found: u1[x] = i;
                ret = (ret + dfs(y, x + 1, u1)) % C;
            }
        }
        return ret;
    }

    writeln(dfs(0, 0, (new int[c])));

}