#include <bits/stdc++.h>
using namespace std;
char a[509][509];
int dp[3][509][509];
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  getchar();
  for (int i = int(1); i <= int(n); i++) {
    for (int j = int(1); j <= int(m); j++) {
      a[i][j] = getchar();
    }
    getchar();
  }
  int maxd = (n + m) / 2;
  for (int x = int(1); x <= int(n); x++) {
    for (int p = int(1); p <= int(n); p++) {
      int y = maxd + 1 - x, q = n + m - p - maxd + 1;
      if (x <= p && y <= q && a[x][y] == a[p][q] && y >= 1 && y <= m &&
          q >= 1 && q <= m) {
        dp[maxd % 2][x][p] = 1;
      }
    }
  }
  for (int i = int(maxd - 1); i >= int(1); i--) {
    for (int x = int(1); x <= int(n); x++) {
      for (int p = int(1); p <= int(n); p++) {
        int y = i + 1 - x, q = n + m - p - i + 1;
        if (x > p || y > q || q > m || q < 1 || y > m || y < 1) {
          dp[i % 2][x][p] = 0;
          continue;
        }
        if (a[x][y] != a[p][q]) {
          dp[i % 2][x][p] = 0;
          continue;
        }
        dp[i % 2][x][p] = 0;
        if (x + 1 <= n && p - 1 >= 1)
          dp[i % 2][x][p] += dp[1 - i % 2][x + 1][p - 1];
        dp[i % 2][x][p] %= 1000000007;
        dp[i % 2][x][p] += dp[1 - i % 2][x][p];
        dp[i % 2][x][p] %= 1000000007;
        if (x + 1 <= n) dp[i % 2][x][p] += dp[1 - i % 2][x + 1][p];
        dp[i % 2][x][p] %= 1000000007;
        if (p - 1 >= 1) dp[i % 2][x][p] += dp[1 - i % 2][x][p - 1];
        dp[i % 2][x][p] %= 1000000007;
      }
    }
  }
  printf("%d\n", dp[1][1][n]);
  return 0;
}
