#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

const int mod = (int)1e8 + 7;
int h, w, pw[11];
char in[12][12];
int dp[2][3][60000];

int main(){
	pw[0] = 1;
	rep(i, 10) pw[i + 1] = pw[i] * 3;
	
	cin >> h >> w;
	rep(i, h) cin >> in[i];
	
	int cur = 0, next = 1;
	dp[0][0][0] = 1;
	
	rep(i, h) rep(j, w){
		memset(dp[next], 0, sizeof(dp[next]));
		rep(l, 3) rep(u, pw[w]) if(dp[cur][l][u]){
			
			int tu = u / pw[j] % 3;
			
			if(in[i][j] == '.'){
				if(tu && l) continue;
				if(l == 0 || j < w - 1) (dp[next][l][u] += dp[cur][l][u]) %= mod;
				continue;
			}
			int rest = in[i][j] - '0' - tu - l;
			rep(nl, 3){
				int nu = rest - nl;
				if(nu < 0 || nu > 2) continue;
				if(nl == 0 || j < w - 1)
					(dp[next][nl][u + pw[j] * (nu - tu)] += dp[cur][l][u]) %= mod;
			}
		}
		swap(cur, next);
	}
	cout << dp[cur][0][0] << endl;
	
	return 0;
}