import sys def input():return sys.stdin.readline().strip() mem={} def calc(a,b,c,d,S,H,W): if S[a][b]!=S[c][d] or a>c or b>d: return 0 if a+b==c+d: return (a==c) and (b==d) if a+b+1==c+d: return (a==c) or (b==d) if not (a*W+b)*H*W+(c*W+d) in mem: mem[(a*W+b)*H*W+(c*W+d)]=calc(a+1,b,c-1,d,S,H,W)+calc(a+1,b,c,d-1,S,H,W)+calc(a,b+1,c-1,d,S,H,W)+calc(a,b+1,c,d-1,S,H,W) mem[(a*W+b)*H*W+(c*W+d)]%=(10**9+7) return mem[(a*W+b)*H*W+(c*W+d)] H,W=map(int,input().split()) S=[input() for i in range(H)] print(calc(0,0,H-1,W-1,S,H,W))