#include <cassert>
#include <cstdio>
#include <cstring>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <queue>
#include <set>
using namespace std;

vector<string> g;
int h, w;

int dp[10][10][3][59049 + 10];
const int mod = 100000007;

void decode(int val, int *ret){
  REP(i,w){
    ret[i] = val % 3;
    val /= 3;
  }
}

int encode(int *a){
  int ret = 0;
  REP(i,w){
    ret *= 3;
    ret += a[w - 1 - i];
  }
  return ret;
}

bool valid(int a, int b, int c, int d){
  int sum = a + b + c + d;
  int mx = max(max(a,b),max(c,d));
  return mx <= sum - mx;
}

int solve(int y, int x, int prev, int val){
  assert(val < 59049 + 10);
  if(y == h && x == 0){
    return val == 0 ? 1 : 0;
  }
  if(x == w){
    if(prev != 0) return 0;
    return solve(y + 1, 0, 0, val);
  }

  if(dp[y][x][prev][val] != -1)
    return dp[y][x][prev][val];

  int a[w + 1]; decode(val, a);
  int in = prev + a[0];

  int ret = 0;

  if(g[y][x] == '.'){
    /*
    REP(migi, 3) REP(sita, 3){
      if((migi + sita + in) % 2 != 0) continue;
      if(!valid(migi, sita, a[0], prev)) continue;

      if(y == h - 1 && sita != 0) continue;
      if(x == w - 1 && migi != 0) continue;

      printf("%d, %d (ue:%d, migi:%d sita:%d, hidari:%d)\n", y, x, a[0], migi, sita, prev);

      a[w] = sita;
      ret += solve(y, x + 1, migi, encode(a + 1));
      ret %= mod;
    }
    */
    if(prev > 0 && a[0] > 0) return 0;
    if(prev > 0){
      if(x != w - 1){
	a[w] = 0;
	ret += solve(y, x + 1, prev, encode(a + 1));
      }
    }else if(a[0] > 0){
      if(y != h - 1){
	a[w] = a[0];
	ret += solve(y, x + 1, 0, encode(a + 1));
      }
    }else{
      a[w] = 0;
      ret += solve(y, x + 1, 0, encode(a + 1));
    }
  }else{
    const int expected = g[y][x] - '0';

    REP(migi, 3){
      const int sita = expected - in - migi;

      if(y == h - 1 && sita != 0) continue;
      if(x == w - 1 && migi != 0) continue;

      if(0 <= sita && sita <= 2){
	// printf("%d, %d (ue:%d, migi:%d sita:%d, hidari:%d)\n", y, x, a[0], migi, sita, prev);

	a[w] = sita;
	ret += solve(y, x + 1, migi, encode(a + 1));
	ret %= mod;
      }
    }
  }

  return dp[y][x][prev][val] = ret;
}


int main(){
  cin >> h >> w;
  g = vector<string>(h);
  REP(i,h) cin >> g[i];

  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, 0, 0) << endl;

  return 0;
}