H,W = map(int,input().split()) S = [input() for _ in range(H)] P = 10 ** 9 + 7 import sys if S[0][0] != S[-1][-1]: print(0) exit() base = 10 mask = (1 << base) - 1 def pack(a,b,c,d): return (a << 30) + (b << 20) + (c << 10) + d def unpack(x): d = x & mask x >>= base c = x & mask x >>= base b = x & mask a = x >> base return (a,b,c,d) from collections import defaultdict d = defaultdict(int) d[pack(0,0,H - 1,W - 1)] = 1 ans = 0 u = H + W - 2 if u % 2 == 0: for _ in range(u // 2): nx = defaultdict(int) for x in d: h,w,hh,ww = unpack(x) for i,j in [(1,0),(0,1)]: for k,l in [(-1,0),(0,-1)]: if h + i < H and w + j < W and hh + k >= 0 and ww + l >= 0: if S[h + i][w + j] == S[hh + k][ww + l]: nx[pack(h + i,w + j,hh + k,ww + l)] += d[pack(h,w,hh,ww)] nx[pack(h + i,w + j,hh + k,ww + l)] %= P d = nx for u in d: h,w,hh,ww = unpack(u) if h == hh and w == ww: ans += d[u] ans %= P print(ans) else: for _ in range(u // 2 + 1): nx = defaultdict(int) if _ < u // 2: for x in d: h,w,hh,ww = unpack(x) for i,j in [(1,0),(0,1)]: for k,l in [(-1,0),(0,-1)]: if h + i < H and w + j < W and hh + k >= 0 and ww + l >= 0: if S[h + i][w + j] == S[hh + k][ww + l]: nx[pack(h + i,w + j,hh + k,ww + l)] += d[x] nx[pack(h + i,w + j,hh + k,ww + l)] %= P else: for x in d: h,w,hh,ww = unpack(x) for i,j in [(1,0),(0,1)]: for k,l in [(-1,0),(0,-1)]: if h + i < H and w + j < W and hh + k >= 0 and ww + l >= 0: if S[h + i][w + j] == S[hh + k][ww + l]: if h + i == hh and w + j == ww and hh + k == h and ww + l == w: ans += d[x] ans %= P d = nx print(ans)