#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m, maxlv, lv, x1, y1, x2, y2, i, j, p, q, d;
  long dp[2][501][501];
  char c[501][501];
  cin >> n >> m;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j) cin >> c[i][j];
  for (i = 0; i <= n; ++i)
    for (j = 0; j <= m; ++j) dp[1][i][j] = -1;
  maxlv = (n + m) / 2;
  if (c[0][0] == c[n - 1][m - 1])
    dp[1][0][0] = 1;
  else
    dp[1][0][0] = -1;
  for (lv = 2; lv <= maxlv; ++lv) {
    for (i = 0; i <= n; ++i)
      for (j = 0; j <= m; ++j) dp[lv % 2][i][j] = -1;
    d = min(lv, max(n, m));
    for (i = 0; i < d; ++i)
      for (j = 0; j < d; ++j) {
        x1 = lv - 1 - i;
        y1 = i;
        x2 = (n - 1) - (lv - 1 - j);
        y2 = (m - 1) - j;
        if ((x1 >= n) || (y1 >= m) || (x2 < 0) || (y2 < 0))
          dp[lv % 2][i][j] = -1;
        else if (c[x1][y1] != c[x2][y2])
          dp[lv % 2][i][j] = -1;
        else {
          dp[lv % 2][i][j] = 0;
          for (p = i - 1; p <= i; ++p)
            for (q = j - 1; q <= j; ++q) {
              if ((p != -1) && (q != -1)) {
                if (dp[(lv - 1) % 2][p][q] != -1)
                  dp[lv % 2][i][j] =
                      (dp[lv % 2][i][j] + dp[(lv - 1) % 2][p][q]) % 1000000007;
              }
            }
        }
      }
  }
  long long ans = 0;
  d = min(maxlv, max(n, m));
  for (i = 0; i < d; ++i)
    for (j = 0; j < d; ++j) {
      x1 = maxlv - 1 - i;
      y1 = i;
      x2 = (n - 1) - (maxlv - 1 - j);
      y2 = (m - 1) - j;
      if ((x1 < n) && (y1 < m) && (x2 >= 0) && (y2 >= 0)) {
        if (dp[maxlv % 2][i][j] != -1) {
          if ((n + m) % 2 == 1) {
            if (((x1 == x2) && (y1 + 1 == y2)) ||
                ((x1 + 1 == x2) && (y1 == y2)))
              ans = (ans + dp[maxlv % 2][i][j]) % 1000000007;
          } else {
            if ((x1 == x2) && (y1 == y2))
              ans = (ans + dp[maxlv % 2][i][j]) % 1000000007;
          }
        }
      }
    }
  cout << ans << endl;
  return 0;
}
