#include using namespace std; const long MOD = 1000000007; long pow[101]; void init(){ pow[0] = 1; for(int i = 1; i <= 100; i++){ pow[i] = pow[i-1]*2; pow[i] %= MOD; } } int main(){ init(); int H, W; cin >> H >> W; char s[100][100]; bool all_free = true; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ cin >> s[i][j]; if(s[i][j] != '?') all_free = false; } } int fc = 0, fr = 0; int bc = 0, br = 0; for(int i = 0; i < H; i++){ int type = -1; for(int j = 0; j < W; j++){ if(s[i][j] == '0'){ if(j%2 == 0){ if(type == 1) br++; else type = 0; }else{ if(type == 0) br++; else type = 1; } } if(s[i][j] == '1'){ if(j%2 == 0){ if(type == 0) br++; else type = 1; }else{ if(type == 1) br++; else type = 0; } } } if(type == -1) fr++; } long ans = 0; if(br == 0) ans += pow[fr]; for(int j = 0; j < W; j++){ int type = -1; for(int i = 0; i < H; i++){ if(s[i][j] == '0'){ if(i%2 == 0){ if(type == 1) bc++; else type = 0; }else{ if(type == 0) bc++; else type = 1; } } if(s[i][j] == '1'){ if(i%2 == 0){ if(type == 0) bc++; else type = 1; }else{ if(type == 1) bc++; else type = 0; } } } if(type == -1) fc++; } if(bc == 0) ans += pow[fc]; if(bc == 0 && br == 0){ if(all_free) ans -= 2; else ans -= 1; } ans %= MOD; ans += MOD; ans %= MOD; cout << ans << endl; }