mod=10**9+7 H,W=map(int,input().split()) S=[input() for i in range(H)] if S[0][0]!=S[-1][-1]: print(0) exit() N=H+W-2 DP=[[[0]*H for i in range(H)] for j in range(N+1)] DP[0][0][H-1]=1 ANS=0 for i in range(N): for j in range(H): for k in range(H): x1,y1=j,i-j x2,y2=k,W-1-(i-(H-1-k)) if y1<0 or y2<0 or y2>=W: continue if abs(x1-x2)+abs(y1-y2)<=1: ANS=(ANS+DP[i][j][k])%mod for l in range(2): for m in range(2): x3,y3=x1+l,y1+(l^1) x4,y4=x2-m,y2-(m^1) if H<=x3 or W<=y3 or x4<0 or y4<0: continue if S[x3][y3]==S[x4][y4]: DP[i+1][j+l][k-m]=(DP[i+1][j+l][k-m]+DP[i][j][k])%mod print(ANS)