#include using namespace std; using mint = atcoder::modint1000000007; int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector A(h); for(auto &&s:A)cin >> s; string s0(w, '?'); for(int i = 0; i < w; i++)s0[i] = (i & 1) + '0'; auto comp = [&](int y, int state){ for(int x = 0; x < w; x++){ if(A[y][x] == '?')continue; if(A[y][x] != (s0[x] ^ state))return false; } return true; }; mint v = comp(0, 0) + comp(0, 1); string s1(w, '?'); bool f = true; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ if(A[y][x] == '?')continue; if(s1[x] == '?'){ s1[x] = A[y][x] ^ (y & 1); continue; } if(A[y][x] != (s1[x] ^ (y & 1))) f = false; } if(y) v = comp(y, 0) * v + comp(y, 1) * v; } A[0] = s1; mint ans = v; if(f)ans += mint(2).pow(count(s1.begin(), s1.end(), '?')) - comp(0, 0) - comp(0, 1); cout << ans.val() << '\n'; }