MOD = 10 ** 9 + 7 h, w = map(int, input().split()) S = [input() for _ in range(h)] if S[0][0] != S[-1][-1]: print(0) exit() def f(i1, i2, j1, j2): return ((i1 * 200 + i2) * 200 + j1) * 200 + j2 def rf(x): j2 = x % 200 x //= 200 j1 = x % 200 x //= 200 i2 = x % 200 i1 = x // 200 return i1, i2, j1, j2 dp = {f(0, 0, h - 1, w - 1): 1} directions = [(1, 0, -1, 0), (0, 1, -1, 0), (1, 0, 0, -1), (0, 1, 0, -1)] for _ in range((h + w) // 2 - 1): ndp = {} for tmp, v in dp.items(): i1, j1, i2, j2 = rf(tmp) for di1, dj1, di2, dj2 in directions: ni1 = i1 + di1 nj1 = j1 + dj1 ni2 = i2 + di2 nj2 = j2 + dj2 if ni1 == h or nj1 == w or ni2 == -1 or nj2 == -1: continue if S[ni1][nj1] == S[ni2][nj2]: tmp = f(ni1, nj1, ni2, nj2) ndp[tmp] = ndp.get(tmp, 0) + v ndp[tmp] %= MOD dp = ndp ans = 0 for tmp, v in dp.items(): i1, j1, i2, j2 = rf(tmp) if abs(i1 - i2) + abs(j1 - j2) <= 1: ans += v ans %= MOD print(ans)