import sys input = sys.stdin.readline H, W = map(int, input().split()) a = [list(input())[: -1] for _ in range(H)] mod = 10 ** 9 + 7 if a[0][0] != a[-1][-1]: print(0) exit(0) from collections import deque as dq Q = dq([(0, H * W - 1)]) d1 = [1, 0] d2 = [-1, 0] dp = [[0] * (H * W) for _ in range(H * W)] dp[0][-1] = 1 vis = [[0] * (H * W) for _ in range(H * W)] while len(Q): u, v = Q.popleft() if vis[u][v]: continue vis[u][v] = 1 i, j = u // W, u % W y, x = v // W, v % W for k in range(2): i2, j2 = i + d1[k], j + d1[~k] if not (i2 in range(H) and j2 in range(W)): continue u2 = i2 * W + j2 for kk in range(2): y2, x2 = y + d2[kk], x + d2[~kk] if not (y2 in range(H) and x2 in range(W)): continue if a[i2][j2] != a[y2][x2]: continue v2 = y2 * W + x2 dp[u2][v2] += dp[u][v] dp[u2][v2] %= mod Q.append((u2, v2)) #print((i, j), (y,x),(i2, j2),(y2,x2)) #print((i, j), (y, x), len(Q)) res = 0 for i in range(H): for j in range(W): res += dp[i * W + j][i * W + j] res %= mod for i in range(H): for j in range(W): for k in range(2): u, v = i + d1[k], j + d1[~k] if u in range(H) and v in range(W) and a[i][j] == a[u][v]: res += dp[i * W + j][u * W + v] res %= mod print(res)