#include using namespace std; char a[105][105], b[105][105]; long long M = 1000000007; long long get(char p[105][105], int n, int m) { for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (p[i][j] != '?') { int tg = (i & 1) ^ p[i][j]; if (p[0][j] == (tg ^ 1)) return -1; p[0][j] = tg; } long long ans = 1; for (int i = 0; i < m; i++) { if (p[0][i] == '?') ans = (ans + ans) % M; } return ans; } int main() { freopen("01.in", "r", stdin); freopen("01.out", "w", stdout); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { char c; cin >> c; a[i][j] = b[j][i] = c; } long long A = get(a, n, m), B = get(b, m, n); if (A == -1 && B == -1) { cout << 0 << endl; } else if (A == -1 || B == -1) { cout << (A + B + 1) % M << endl; } else { cout << (A + B - 1) % M << endl; } }