#include <bits/stdc++.h>
using namespace std;
int n, m;
long long dp[2][550][550];
char s[550][550];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; i++) scanf("%s", s[i]);
    if (n == 1 && m == 1) {
      printf("1\n");
      continue;
    }
    int cur = 0;
    dp[cur][0][n - 1] = (s[0][0] == s[n - 1][m - 1]) ? 1 : 0;
    for (int i = 1; i <= (n + m - 3) / 2; i++) {
      memset(dp[1 - cur], 0, sizeof dp[1 - cur]);
      for (int j = 0; j <= i; j++) {
        int tmp = n + m - 2 - i;
        for (int k = n - 1; k >= tmp - m + 1; k--) {
          if (s[j][i - j] == s[k][tmp - k]) {
            if (j && k + 1 < n) dp[1 - cur][j][k] += dp[cur][j - 1][k + 1];
            if (j) dp[1 - cur][j][k] += dp[cur][j - 1][k];
            if (k + 1 < n) dp[1 - cur][j][k] += dp[cur][j][k + 1];
            dp[1 - cur][j][k] += dp[cur][j][k];
            dp[1 - cur][j][k] %= 1000000007;
          }
        }
      }
      cur = 1 - cur;
    }
    long long ans = 0;
    int up = (n + m - 3) / 2;
    int down = n + m - 2 - up;
    for (int i = 0; i <= up; i++) {
      for (int j = n - 1; j >= down - m + 1; j--) {
        if ((n + m - 1) & 1) {
          if (abs(i - j) + abs(up - i - down + j) == 2) {
            if (i == j || up - i == down - j) {
              ans += dp[cur][i][j];
            } else {
              ans += dp[cur][i][j] * 2;
            }
          }
        } else {
          if (abs(i - j) + abs(up - i - down + j) == 1) ans += dp[cur][i][j];
        }
        ans %= 1000000007;
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
