#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 7;

int n, m;
string a[2005];

int hor[2005], ver[2005], diag[5005];
int dp[2005][2005];

int offset(int x) {
	return x + 2500;
}

int add(int x, int y) {
	return ((long long) (x + y)) % INF;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] = "." + a[i];
	}

	dp[1][1] = hor[1] = ver[1] = diag[offset(1 - 1)] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == '#') {
				hor[i] = ver[j] = diag[offset(i - j)] = 0;
				continue;
			}
			if (i == 1 && j == 1) continue;

			dp[i][j] = add(add(hor[i], ver[j]), diag[offset(i - j)]);

			hor[i] = add(hor[i], dp[i][j]);
			ver[j] = add(ver[j], dp[i][j]);
			diag[offset(i - j)] = add(diag[offset(i - j)], dp[i][j]);
		}
	}

	cout << dp[n][m] << "\n";

	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e18;
const ll MOD = 1000000007;
int N, M;
void dfs(int t, vector<P> &V, set<int> &checked, vector<vector<int>> &G) {
    for(auto &i : G[t]) {
        if(checked.count(i))
            continue;
        V.push_back(P(i, t));
        checked.insert(i);
        dfs(i, V, checked, G);
    }
    return;
}
int C[25];
ll search(int now_id, vector<P> &V, vector<vector<int>> &G) {
    if(now_id == V.size()) {
        for(auto &s : V) {
            for(auto &t : G[s.first]) {
                if(C[s.first] == C[t]) {
                    return 0;
                }
            }
        }
        return 1;
    }
    if(now_id == 0) {
        ll ret = 0;
        C[V[now_id].first] = 1;
        ret += search(now_id + 1, V, G);
        C[V[now_id].first] = 0;
        C[V[now_id].first] = 2;
        ret += search(now_id + 1, V, G);
        C[V[now_id].first] = 0;
        C[V[now_id].first] = 3;
        ret += search(now_id + 1, V, G);
        C[V[now_id].first] = 0;
        return ret;
    } else {
        ll ret = 0;
        for(int i = 1; i <= 3; ++i) {
            if(C[V[now_id].second] != i) {
                C[V[now_id].first] = i;
                ret += search(now_id + 1, V, G);
                C[V[now_id].first] = 0;
            }
        }
        return ret;
    }
}
int main() {
    cin >> N >> M;
    vector<vector<int>> G(N);
    REP(i, M) {
        int A, B;
        cin >> A >> B, A--, B--;
        G[A].push_back(B), G[B].push_back(A);
    }
    ll ans = 1;
    set<int> checked;
    REP(i, N) {
        if(checked.count(i))
            continue;
        vector<P> V;
        set<int> s;
        s.insert(i);
        V.push_back(P(i, -1));
        dfs(i, V, s, G);
        for(auto &x : V) {
            checked.insert(x.first);
        }
        ans *= search(0, V, G);
    }
    cout << ans << endl;
}