#include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) using ll = long long; using namespace std; const int mod = 1e9+7; int count1(vector const & f) { int h = f.size(); int w = f.front().size(); ll acc = 1; repeat (x,w) { int sats = 0; repeat (p,2) { bool sat = true; repeat (y,h) { int clr = (x % 2) ^ p ^ (y % 2); if (f[y][x] != '?' and f[y][x] - '0' != clr) { sat = false; break; } } sats += sat; } acc = acc * sats % mod; if (not acc) break; } return acc; } int count2(vector const & f) { int h = f.size(); int w = f.front().size(); int acc = 0; repeat (p,2) { bool sat = true; repeat (y,h) { repeat (x,w) { int clr = p ^ (x % 2) ^ (y % 2); if (f[y][x] != '?' and f[y][x] - '0' != clr) { sat = false; break; } } } acc += sat; } return acc; } vector tr(vector const & f) { int h = f.size(); int w = f.front().size(); vector g(w, string(h, '\0')); repeat (x,w) repeat (y,h) g[x][y] = f[y][x]; return g; } int main() { int h, w; cin >> h >> w; vector f(h); repeat (y,h) cin >> f[y]; ll ans = 0; ans += count1(f); ans += count1(tr(f)); ans -= count2(f); ans = (ans + mod) % mod; cout << ans << endl; return 0; }