#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=10 ** 9 + 7 import sys input=sys.stdin.readline h,w=map(int,input().split()) if h == w == 1: print(1) exit() s=[input().rstrip() for _ in range(h)] dp = [[[0] * h for _ in range(h)] for _ in range(h + w - 1)] if s[0][0] == s[-1][-1]: dp[0][0][h-1] = 1 ans = 0 for i in range(1,(h+w-1) // 2 + 1): for sh in range(h): sw = i - sh if 0 <= sh < h and 0 <= sw < w: for gh in range(h): gw = h + w - 2 - i - gh if 0 <= gh < h and 0 <= gw < w: if s[sh][sw] == s[gh][gw]: tmp1 = 0 if sh > 0 and gh < h - 1: tmp1 += dp[i-1][sh - 1][gh + 1] if sh > 0 and gw < w - 1: tmp1 += dp[i-1][sh-1][gh] tmp1 %= mod if sw > 0 and gh < h - 1: tmp1 += dp[i-1][sh][gh + 1] tmp1 %= mod if sw > 0 and gw < w - 1: tmp1 += dp[i-1][sh][gh] tmp1 %= mod if gh >= sh and gw >= sw and gh + gw - sh - sw <= 1: ans += tmp1 ans %= mod else: dp[i][sh][gh] = tmp1 print(ans) #print(dp) else: print(0)