#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

struct uf {
private:
	vector<int> par, ran;
public:
	void init(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

struct perm {
private:
	int sz;
	vector<ll> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		rep1(i, sz - 1) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		per(i, sz - 1) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
};

int h, w;
ll mod_inverse(ll x, ll n = mod - 2) {
	ll ret = 1;
	while (n) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}
int b[100][100];
int cnt;
bool used[200];
queue<P> cur;
void calc() {
	h /= 2; w /= 2;
	uf u; u.init(h + w+1);
	rep(i, h) {
		rep(j, w) {
			if (b[i][j]) {
				u.unite(i, h + j);
				cnt++;
			}
		}
	}
	int g = h + w;
	rep(i, h + w) {
		if (u.same(g, i))continue;
		cnt++; u.unite(g, i);
	}
	cnt -= h + w;
}
void solve() {
	cin >> h >> w;
	vector<char> v;
	rep(i, h) {
		rep(j, w) {
			char t; cin >> t; v.push_back(t);
		}
	}
	perm p(200);
	int alf[26] = {};
	rep(i, v.size()) {
		alf[v[i] - 'a']++;
	}
	ll sum = 1;
	rep(i, h / 2) {
		rep(j, w / 2) {
			vector<char> e;
			e.push_back(v[i*w + j]);
			e.push_back(v[i*w + w - 1 - j]);
			e.push_back(v[(h - 1 - i)*w + j]);
			e.push_back(v[(h - 1 - i)*w + w - 1 - j]);
			sort(e.begin(), e.end());
			ll z = 4;
			int tmp = 0;
			rep(k, 4) {
				tmp++;
				int le = k;
				while (k + 1 < 4 && e[k + 1] == e[k])k++;
				sum = sum * p.comb(z, k - le + 1) % mod;
				z -= k - le + 1;
			}
			if (tmp == 4) {
				b[i][j] = 1;
			}
		}
	}
	if (h % 2) {
		int ch = h / 2; ch *= w;
		bool f = false;
		rep(j, w / 2) {
			if (v[ch + j] != v[ch + w - 1 - j])f = true;
		}
		if (f)sum = sum * 2 % mod;
	}
	if (w % 2) {
		int cw = w / 2;
		bool f = false;
		rep(i, h / 2) {
			if (v[i*w + cw] != v[(h - 1 - i)*w + cw])f = true;
		}
		if (f)sum = sum * 2 % mod;
	}
	calc();
	rep(i, cnt) {
		sum = sum * (mod + 1) / 2 % mod;
	}
	cout << sum << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 384