import sys from operator import itemgetter from collections import defaultdict, deque import heapq from heapq import heapify, heappop, _heapify_max, heappush from bisect import bisect_left, bisect_right import math import itertools import copy stdin=sys.stdin #sys.setrecursionlimit(10 ** 7) ## import pypyjit ## pypyjit.set_param('max_unroll_recursion=-1') ip=lambda: int(sp()) fp=lambda: float(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() Yp=lambda:print('Yes') Np=lambda:print('No') inf = 1 << 60 inf = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 eps = 1e-9 sortkey1 = itemgetter(0) sortkey2 = lambda x: (x[0], x[1]) ############################################################### def f(s): cnt = 1 for si in s: c = all(x != '1' for x in si[::2]) & all(x != '0' for x in si[1::2]) c += all(x != '0' for x in si[::2]) & all(x != '1' for x in si[1::2]) cnt *= c % mod return cnt H, W = lp() S = [sp() for _ in range(H)] ans = f(S) + f(zip(*S)) ans %= mod r = '01' c1 = c2 = 1 for h in range(H): for w in range(W): if S[h][w] == r[(h + w) % 2]: c1 = 0 if S[h][w] == r[(h + w + 1) % 2]: c2 = 0 ans -= c1 + c2 ans %= mod print(ans)