mod = 1000000007 def main(): import sys input = sys.stdin.readline H, W = map(int, input().split()) G = [] for _ in range(H): G.append(input().rstrip('\n')) dp = [[0] * W for _ in range(H)] if G[0][0] != G[-1][-1]: print(0) exit() dp[0][H-1] = 1 for hw in range((H + W - 2) // 2): dp_new = [[0] * W for _ in range(H)] for hl in range(H): wl = hw - hl if wl < 0 or wl >= W: continue for hr in range(H): wr = H + W - 2 - hw - hr if wr < 0 or wr >= W: continue if hl != H - 1: hl_new = hl + 1 sl = G[hl_new][wl] if hr != 0: hr_new = hr - 1 sr = G[hr_new][wr] if sl == sr: dp_new[hl_new][hr_new] = (dp_new[hl_new][hr_new] + dp[hl][hr])%mod if wr != 0: wr_new = wr - 1 sr = G[hr][wr_new] if sl == sr: dp_new[hl_new][hr] = (dp_new[hl_new][hr] + dp[hl][hr]) % mod if wl != W - 1: hl_new = hl sl = G[hl_new][wl+1] if hr != 0: hr_new = hr - 1 sr = G[hr_new][wr] if sl == sr: dp_new[hl_new][hr_new] = (dp_new[hl_new][hr_new] + dp[hl][hr]) % mod if wr != 0: wr_new = wr - 1 sr = G[hr][wr_new] if sl == sr: dp_new[hl_new][hr] = (dp_new[hl_new][hr] + dp[hl][hr]) % mod dp = dp_new if (H + W) & 1: ans = 0 for hl in range(H): wl = (H + W - 2) // 2 - hl for hr in range(H): wr = (H + W - 2) // 2 + 1 - hr if abs(hl - hr) + abs(wl - wr) == 1: ans = (ans + dp[hl][hr])%mod print(ans) else: ans = 0 for hl in range(H): ans = (ans + dp[hl][hl])%mod print(ans) if __name__ == '__main__': main()