#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 H, W = map(int, readline().split()) S = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W] answer = 0 for _ in range(2): S = S.T p = 1 for row in S: x = 0 if np.all(row[::2] != b'0') and np.all(row[1::2] != b'1'): x += 1 if np.all(row[::2] != b'1') and np.all(row[1::2] != b'0'): x += 1 p *= x answer += p if all((np.all(S[::2, ::2] != b'0'), np.all(S[1::2, 1::2] != b'0'), np.all(S[1::2, ::2] != b'1'), np.all(S[::2, 1::2] != b'1'))): answer -= 1 if all((np.all(S[::2, ::2] != b'1'), np.all(S[1::2, 1::2] != b'1'), np.all(S[1::2, ::2] != b'0'), np.all(S[::2, 1::2] != b'0'))): answer -= 1 print(answer % MOD)