#include <bits/stdc++.h>
using namespace std;
long long dp[2][510][510];
char mp[510][510];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
  }
  int len = (n + m) / 2;
  int t = 0;
  for (int i = len - 1; i >= 0; i--) {
    memset(dp[t], 0, sizeof(dp[t]));
    for (int j = 1; j <= m; j++) {
      int x1 = i + 2 - j, y1 = j;
      if (x1 < 1 || x1 > n) continue;
      for (int k = j; k <= m; k++) {
        int x2 = (n + m) - k - i, y2 = k;
        if (x2 < 1 || x2 > n) continue;
        if (x2 < x1 || y2 < y1) continue;
        if (mp[x1][y1] != mp[x2][y2]) continue;
        if (i == len - 1)
          dp[t][j][k] = 1;
        else {
          dp[t][j][k] =
              (dp[t][j][k] + dp[1 - t][j + 1][k] + dp[1 - t][j][k - 1] +
               dp[1 - t][j + 1][k - 1] + dp[1 - t][j][k]) %
              1000000007;
        }
      }
    }
    t = 1 - t;
  }
  cout << dp[1 - t][1][m] << endl;
  return 0;
}
