H, W = map(int, input().split()) table = {} for i in range(H): for j, v in enumerate(list(input())): if v != '?': if i not in table: table[i] = {} table[i][j] = int(v) exp1= H exp2= W dup = 2 chk = -1 v_chk = [-1] * W for i, row in table.items(): h_chk = -1 for j, v in row.items(): if chk == -1: chk = (i + j + v) % 2 dup = 1 else: if chk != (i + j + v) % 2: dup = 0 if h_chk == -1: h_chk = (j + v) % 2 if exp1 > 0: exp1 -= 1 else: if h_chk != (j + v) % 2: exp1 = -1 if v_chk[j] == -1: v_chk[j] = (i + v) % 2 if exp2 > 0: exp2 -= 1 else: if v_chk[j] != (i + v) % 2: exp2 = -1 if exp1 == -1 and exp2 == -1: break MOD = 1000000007 ans = 0 if exp1 != -1: ans += pow(2, exp1, MOD) if exp2 != -1: ans += pow(2, exp2, MOD) - dup ans %= MOD print(ans)