#include int main() { int n, m, c = 0, d = 0; char b[111][111]; scanf ("%d %d", &n, &m); for (int i = 0; i < n; i++){ scanf ("%s", b[i]); for (int j = 0; j < m; j++) if (b[i][j] != '?'){ c += (b[i][j] - '0' + i + j) % 2; d++; } } int u = 0; for (int i = 0; i < n; i++){ int c[2] = { 0, }; for (int j = 0; j < m; j++) if (b[i][j] != '?'){ c[(b[i][j] - '0' + j) % 2]++; } if (c[0] && c[1]){ u = -1; break; } if (!c[0] && !c[1]) u++; } int v = 0; for (int j = 0; j < m; j++){ int c[2] = { 0, }; for (int i = 0; i < n; i++) if (b[i][j] != '?'){ c[(b[i][j] - '0' + i) % 2]++; } if (c[0] && c[1]){ v = -1; break; } if (!c[0] && !c[1]) v++; } const long long mod = 1000000007; long long U = 1, V = 1; if (u < 0) U = 0; else while (u--) U = U * 2 % mod; if (v < 0) V = 0; else while (v--) V = V * 2 % mod; long long A = (U + V) % mod; if (c == 0) A = (A + mod - 1) % mod; if (c == d) A = (A + mod - 1) % mod; printf ("%lld\n", A); return 0; }