#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define foreach(it,v) for (__typeof((v).end()) it = (v).begin(); it != (v).end(); it++)
typedef long long ll;
typedef pair <int, int> PII;
const int N = 15;
const int Mod = 10007;
int m, n;
ll pw[N];
char mat[N][N];
map < ll, int > f;

void add(int &t, int w) {
	t += w;
	if (t >= Mod) t-= Mod;
}

ll encode(const vector <int> &v) {
	ll res = 0;
	rep (i, n) res += (ll)(v[i] + 1) << (i * 4);
	return res;
}

int get(ll mask, int i) {
	return (mask >> (i * 4) & 15) - 1;
}

int main() {
	pw[0] = 1;
	for (int i = 1; i < 15; i++) pw[i] = pw[i - 1] * 16;
	scanf("%d%d", &m, &n);
	rep (i, m) scanf("%s", mat[i]);
	f[encode(vector <int> (n, -1))] = 1;
	for (char c = 'a'; c <= 'z'; c++) {
		rep (i, n) foreach (it, f) {
			int w = f[it->first];
			int vi = get(it->first, i);
			if (vi + 1 < m 
				&& (mat[vi + 1][i] == '.' || mat[vi + 1][i] == c) 
				&& vi + 1 <= (i ? get(it->first, i - 1) : m)) {
				add(f[it->first + pw[i]], w);
			}
		}
	}
	printf("%d\n", f[encode(vector <int> (n, m - 1))]);
}
