H, W = map(int, input().split()) S = [] for i in range(H): S.append(list(input())) from collections import * Q = deque() if S[0][0] != S[-1][-1]: print(0) exit() mod = 10**9 + 7 Q.append((0, 0, H - 1, W - 1)) D = defaultdict(int) D[(0, 0, H - 1, W - 1)] = 1 dx = [1, 0] dy = [0, 1] ans = 0 SS = set() seen = set() while Q: t = Q.popleft() sx, sy, gx, gy = t if gx + gy <= sx + sy + 1: if abs(sx - gx) + abs(sy - gy) <= 1 and t not in SS: SS.add(t) ans += D[(sx, sy, gx, gy)] ans %= mod continue for a in range(2): for b in range(2): nsx = sx + dx[a] nsy = sy + dy[a] ngx = gx - dx[b] ngy = gy - dy[b] if S[nsx][nsy] != S[ngx][ngy]: continue nt = (nsx, nsy, ngx, ngy) D[nt] += D[t] D[nt] %= mod if nt in seen: continue seen.add(nt) Q.append(nt) print(ans)