#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384626433;
const long long mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-12;
template <class T>
T gcd(T a, T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
const int maxn = 505;
int dp[2][maxn][maxn];
char mp[maxn][maxn];
const int dfr[4] = {1, 1, 0, 0}, dfc[4] = {0, 0, 1, 1}, dtr[4] = {0, -1, 0, -1},
          dtc[4] = {-1, 0, -1, 0};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%s", mp[i]);
  }
  if (mp[0][0] != mp[n - 1][m - 1]) {
    printf("0\n");
    return 0;
  }
  memset(dp, 0, sizeof(dp));
  int(*now)[maxn] = dp[0], (*nxt)[maxn] = dp[1];
  now[0][n - 1] = 1;
  int stp = n + m - 2;
  for (int t = 0; t + 1 < stp; t += 2) {
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if (now[i][j] == 0) continue;
        int fr = i, fc = t / 2 - i, tr = j, tc = m - 1 - (t / 2 - (n - 1 - j));
        for (int k = 0; k < 4; k++) {
          int nfr = fr + dfr[k], nfc = fc + dfc[k], ntr = tr + dtr[k],
              ntc = tc + dtc[k];
          if (nfr >= n || nfc >= m || ntr < 0 || ntc < 0) continue;
          if (nfr > ntr || nfc > ntc) continue;
          if (mp[nfr][nfc] != mp[ntr][ntc]) continue;
          nxt[nfr][ntr] += now[fr][tr];
          nxt[nfr][ntr] %= mod;
        }
      }
    }
    int(*tmp)[maxn] = now;
    now = nxt;
    nxt = tmp;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        nxt[i][j] = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += now[i][i];
    ans %= mod;
  }
  if (stp % 2) {
    for (int i = 1; i < n; i++) {
      ans += now[i - 1][i];
      ans %= mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}
