#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	int H, W; cin >> H >> W;
	vector<string> a(H);
	rep(y, H) cin >> a[y];
	ll ans = 1;
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++) {
			int _y = H - 1 - y, _x = W - 1 - x;
			if (y > _y || x > _x) continue;
			if (y < _y && x < _x) {
				map<char, int> mp;
				mp[a[y][x]]++;
				mp[a[y][_x]]++;
				mp[a[_y][x]]++;
				mp[a[_y][_x]]++;
				if (mp.size() == 2) {
					int ma = 0;
					for (auto z: mp) ma = max(ma, z.second);
					if (ma == 2) ans = ans * 6 % MOD;
					else ans = ans * 4 % MOD;
				}
				if (mp.size() == 3) ans = ans * 12 % MOD;
				if (mp.size() == 4) {
					ans = ans * 12 % MOD;
					a[y][x] = '*';
				}
			}
			if (y == _y && x < _x) if (a[y][x] != a[y][_x]) a[y][x] = '*';
			if (y < _y && x == _x) if (a[y][x] != a[_y][x]) a[y][x] = '*';
		}
	union_find uf((H / 2) * (W / 2));
	for (int y = 0; y < H; y++) {
		int _y = H - 1 - y;
		if (y < _y) {
			for (int x = 0; x < W / 2; x++)
				for (int _x = x + 1; _x < W / 2; _x++)
					if (a[y][x] == '*' && a[y][_x] == '*')
						uf.unite(y * (W / 2) + x, y * (W / 2) + _x);
		}
	}
	for (int x = 0; x < W; x++) {
		int _x = W - 1 - x;
		if (x < _x) {
			for (int y = 0; y < H / 2; y++)
				for (int _y = y + 1; _y < H / 2; _y++)
					if (a[y][x] == '*' && a[_y][x] == '*')
						uf.unite(y * (W / 2) + x, _y * (W / 2) + x);
		}
	}
	vector<set<int> > Y((H / 2) * (W / 2)), X((H / 2) * (W / 2));
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++) {
			int _y = H - 1 - y, _x = W - 1 - x;
			if (y < _y && x < _x) {
				if (a[y][x] == '*') {
					int k = uf.find(y * (W / 2) + x);
					Y[k].insert(y);
					X[k].insert(x);
				}
			}
		}
	for (int k = 0; k < (H / 2) * (W / 2); k++)
		if (!Y[k].empty()) {
			int t = Y[k].size() + X[k].size();
			t--;
			while (t--) ans = ans * 2 % MOD;
		}
	for (int y = 0; y < H; y++) {
		int _y = H - 1 - y;
		if (y == _y) {
			bool ok = false;
			for (int x = 0; x < W; x++)
				if (a[y][x] == '*')
					ok = true;
			if (ok) ans = ans * 2 % MOD;
		}
	}
	for (int x = 0; x < W; x++) {
		int _x = W - 1 - x;
		if (x == _x) {
			bool ok = false;
			for (int y = 0; y < H; y++)
				if (a[y][x] == '*')
					ok = true;
			if (ok) ans = ans * 2 % MOD;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408