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() from collections import defaultdict d = defaultdict(int) d[(0,0,H - 1,W - 1)] = 1 ans = 0 for _ in range(H + W - 2): nx = defaultdict(int) for h,w,hh,ww in d: if h == hh and w == ww: ans += d[(h,w,hh,ww)] ans %= P continue 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[(h + i,w + j,hh + k,ww + l)] += d[(h,w,hh,ww)] nx[(h + i,w + j,hh + k,ww + l)] %= P d = nx print(ans)