#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define INF 0x3FFFFFFF
#define MN 2005
using namespace std;
int a[MN][MN],len[MN][MN],q[MN];
int n,m,p,ans,tp;
char c[MN];

inline int read()
{
	int n=0,f=1; char c=getchar();
	while (c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
	while (c>='0' && c<='9') {n=n*10+c-'0'; c=getchar();}
	return n*f;
}

int main()
{
	register int i,j;
	n=read(); m=read();
	for (i=1;i<=n;++i)
	{
		scanf("%s",c+1);
		for (j=1;j<=m;++j) a[i][j]=(c[j]=='#'?1:0);
	}
	for (i=1;i<n;++i)
		for (j=1;j<=m;++j) a[i][j]=a[i][j]^a[i+1][j];
	for (i=1;i<n;++i)
		for (j=1;j<m;++j) a[i][j]=a[i][j]^a[i][j+1];
	for (i=1;i<n;++i)
		for (j=1;j<m;++j)
			if (a[i][j]) len[i][j]=0;
			else len[i][j]=len[i-1][j]+1;
//	for (i=1;i<n;++i)
//		for (j=1;j<m;++j)	
	for (i=1;i<n;++i)
	{
		for (j=1;j<m;++j)
		{
			for (;tp&&len[i][j]<=len[i][q[tp]];--tp) ans=max(ans,(j-1-q[tp-1]+1)*(len[i][q[tp]]+1));
			q[++tp]=j;
		}
		for (;tp;--tp) ans=max(ans,(m-1-q[tp-1]+1)*(len[i][q[tp]]+1));
	}
	printf("%d",max(ans,n));
}
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

const int bound = 1000*1000+10;
bool besucht[bound];

void init(){
	for( int i = 0; i < bound; ++i ) besucht[i] = false;
}

int no(){
	cout << 0 << endl;
	return 0;
}

int main(){
	int n, m; cin >> n >> m;
	vector<int> a(n);
	vector<int> b(m);
	for( auto &k : a ){
		cin >> k;
		if( besucht[k] ) return no();
		besucht[k] = true;
	}
	init();
	for( auto &k : b ){
		cin >> k;
		if( besucht[k] ) return no();
		besucht[k] = true;
	}
	sort( a.begin(), a.end() );
	sort( b.begin(), b.end() );
	ll ans = 1;
	for( int k = 1; k <= n*m; ++k ){
		bool ares = binary_search( a.begin(), a.end(), k );
		bool bres = binary_search( b.begin(), b.end(), k );
		ll comb = 1;
		if( !bres ) comb *= (b.end() - lower_bound( b.begin(), b.end(), k ));
		if( !ares ) comb *= (a.end() - lower_bound( a.begin(), a.end(), k ));
		if( !ares && !bres ) comb -= n*m-k;
		ans *= comb;
		ans %= mod;
	}
	cout << ans << endl;
}