#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int maxn = 505;
char a[maxn][maxn];
int dp[2][maxn][maxn];
int main() {
  int n, m, x1, y1, x2, y2, ans, now, pre;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
    if (a[1][1] != a[n][m]) {
      puts("0");
      continue;
    }
    int step = (n + m) / 2;
    memset(dp, 0, sizeof dp);
    now = 1, pre = 0;
    dp[now][1][m] = 1;
    ans = 0;
    for (int i = 1; i <= step; i++) {
      now ^= 1;
      pre ^= 1;
      memset(dp[now], 0, sizeof dp[now]);
      for (int j = max(1, i + 1 - n); j <= i && j <= m; j++) {
        x1 = i - j + 1;
        y1 = j;
        for (int k = max(1, m - i + 1); k <= n + m - i && k <= m; k++) {
          x2 = n + m - i - k + 1;
          y2 = k;
          if (i == step && abs(x1 - x2) + abs(y1 - y2) <= 1) {
            ans += dp[pre][j][k];
            ans %= MOD;
          }
          if (x1 + 1 <= n && x2 - 1 >= 1 && a[x1 + 1][y1] == a[x2 - 1][y2]) {
            dp[now][j][k] += dp[pre][j][k];
            dp[now][j][k] %= MOD;
          }
          if (x1 + 1 <= n && y2 - 1 >= 1 && a[x1 + 1][y1] == a[x2][y2 - 1]) {
            dp[now][j][k - 1] += dp[pre][j][k];
            dp[now][j][k - 1] %= MOD;
          }
          if (y1 + 1 <= m && x2 - 1 >= 1 && a[x1][y1 + 1] == a[x2 - 1][y2]) {
            dp[now][j + 1][k] += dp[pre][j][k];
            dp[now][j + 1][k] %= MOD;
          }
          if (y1 + 1 <= m && y2 - 1 >= 1 && a[x1][y1 + 1] == a[x2][y2 - 1]) {
            dp[now][j + 1][k - 1] += dp[pre][j][k];
            dp[now][j + 1][k - 1] %= MOD;
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
