import pypyjit pypyjit.set_param("max_unroll_recursion=-1") import sys sys.setrecursionlimit(10**7) from functools import cache MOD = 10**9+7 H,W = list(map(int,input().split())) S = [input() for _ in range(H)] dy = [0,1] dx = [1,0] ddy = [0,-1] ddx = [-1,0] @cache def f(y,x,yy): xx = (H-1 + W-1) - yy - x - y if(y+x == (H+W-2)//2):return int(abs(y - yy) + abs(x - xx) <= 1) ret = 0 for i in range(2): next_y = y + dy[i] next_x = x + dx[i] if(next_y < 0 or H <= next_y):continue if(next_x < 0 or W <= next_x):continue for j in range(2): next_yy = yy + ddy[j] next_xx = xx + ddx[j] if(next_yy < 0 or H <= next_yy):continue if(next_xx < 0 or W <= next_xx):continue if(S[next_y][next_x] != S[next_yy][next_xx]):continue ret += f(next_y, next_x, next_yy) ret %= MOD return ret print(f(0,0,H-1) if S[0][0] == S[-1][-1] else 0)