from itertools import product from functools import cache MOD = 10**9 + 7 H, W = map(int, input().split()) S = [] for i in range(H): S.append(input()) @cache def f(r1, c1, r2, c2) -> int: if r1 == r2 and c1 == c2: return 1 if r1 == r2 and c1+1 == c2: return 1 if S[r1][c1] == S[r2][c2] else 0 if r1+1 == r2 and c1 == c2: return 1 if S[r1][c1] == S[r2][c2] else 0 if S[r1][c1] != S[r2][c2]: return 0 res = 0 for (dr1, dc1), (dr2, dc2) in product([(0, 1), (1, 0)], [(0, -1), (-1, 0)]): nr1 = r1 + dr1 nc1 = c1 + dc1 nr2 = r2 + dr2 nc2 = c2 + dc2 if nr1 > nr2: continue if nc1 > nc2: continue res += f(nr1, nc1, nr2, nc2) res %= MOD return res ans = f(0, 0, H-1, W-1) print(ans)