import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 from collections import defaultdict h, w = LI() ss = [SI() for _ in range(h)] if ss[0][0] != ss[h-1][w-1]: print(0) exit() dij = [(0, 1, 0, -1), (1, 0, 0, -1), (0, 1, -1, 0), (1, 0, -1, 0)] dp = defaultdict(int) dp[0, 0, h-1, w-1] = 1 n = h+w-1 for _ in range((n-1)//2): ndp = defaultdict(int) for (i, j, u, v), pre in dp.items(): for di, dj, du, dv in dij: ni, nj, nu, nv = i+di, j+dj, u+du, v+dv if not 0 <= ni < h: continue if not 0 <= nj < w: continue if not 0 <= nu < h: continue if not 0 <= nv < w: continue if ss[ni][nj] != ss[nu][nv]: continue ndp[ni, nj, nu, nv] += pre ndp[ni, nj, nu, nv] %= md dp = ndp # pDB(dp) ans = 0 mid = (n-1)//2 if n & 1: for i in range(h): j = mid-i if not 0 <= j < w: continue ans += dp[i, j, i, j] ans %= md else: for i in range(h): j = mid-i if not 0 <= j < w: continue for u, v in [(i+1, j), (i, j+1)]: if 0 <= u < h and 0 <= v < w and ss[i][j] == ss[u][v]: ans += dp[i, j, u, v] ans %= md print(ans)