#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n, m;
char board[501][501];
long long dp[2][501][501];
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)n; i++) {
    for (int j = 0; j < (int)m; j++) {
      cin >> board[i][j];
    }
  }
  int repNum = (n + m - 2) / 2;
  bool b = false;
  if (board[0][0] == board[n - 1][m - 1]) dp[b][0][m - 1] = 1;
  for (int i = 0; i < (int)repNum; i++) {
    b = !b;
    for (int j = 0; j < (int)501; j++) {
      for (int k = 0; k < (int)501; k++) {
        dp[b][j][k] = 0;
      }
    }
    int j = i + 1;
    int y = j + 1;
    while (y--) {
      int x = j - y;
      if (y >= n) continue;
      if (x >= m) break;
      int y1 = n;
      for (int x1 = m - 1 - j; x1 < (int)m; x1++) {
        y1--;
        if (y1 < 0 || y1 < y) break;
        if (x1 < 0 || x1 < x) continue;
        if (board[y][x] == board[y1][x1]) {
          if (y - 1 >= 0) {
            if (x1 + 1 < m) dp[b][x][x1] += dp[!b][x][x1 + 1];
            dp[b][x][x1] += dp[!b][x][x1];
          }
          if (x - 1 >= 0) {
            if (x1 + 1 < m) dp[b][x][x1] += dp[!b][x - 1][x1 + 1];
            dp[b][x][x1] += dp[!b][x - 1][x1];
          }
          dp[b][x][x1] %= mod;
        }
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < (int)repNum + 1; i++) {
    int y = repNum - i, x = i;
    if (x >= m || y < 0) break;
    if (y >= n) continue;
    int l = max(n, m);
    for (int j = 0; j < (int)l; j++) ret = (ret + dp[b][x][j]) % mod;
  }
  cout << ret << endl;
  return 0;
}
