#include <bits/stdc++.h>
using namespace std;
long long n, m, ans, dp[2][505][505];
char t[505][505];
int main() {
  scanf("%lld %lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", t[i] + 1);
  }
  if (t[1][1] != t[n][m]) {
    puts("0");
    return 0;
  }
  dp[0][1][n] = 1;
  int o = 0;
  for (long long i = 2; i <= (n + m) / 2; i++) {
    o ^= 1;
    for (int j = 0; j <= 504; j++)
      for (int k = 0; k <= 504; k++) dp[o][j][k] = 0;
    int y1, y2;
    for (int x1 = 1; x1 <= min(n, i); x1++) {
      for (int x2 = n; x2 >= max(1ll, n - i); x2--) {
        y1 = i - x1 + 1, y2 = m - (i - (n - x2)) + 1;
        if (t[x1][y1] == t[x2][y2]) {
          dp[o][x1][x2] =
              (dp[o][x1][x2] + dp[o ^ 1][x1 - 1][x2 + 1]) % 1000000007;
          dp[o][x1][x2] = (dp[o][x1][x2] + dp[o ^ 1][x1][x2 + 1]) % 1000000007;
          dp[o][x1][x2] = (dp[o][x1][x2] + dp[o ^ 1][x1 - 1][x2]) % 1000000007;
          dp[o][x1][x2] = (dp[o][x1][x2] + dp[o ^ 1][x1][x2]) % 1000000007;
        }
      }
    }
  }
  if ((n + m) % 2 == 0) {
    for (int x1 = 1; x1 <= n; x1++) {
      ans = (ans + dp[o][x1][x1]) % 1000000007;
    }
  } else {
    for (int x1 = 1; x1 <= n; x1++) {
      ans = (ans + dp[o][x1][x1]) % 1000000007;
      ans = (ans + dp[o][x1][x1 + 1]) % 1000000007;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
