#include <bits/stdc++.h>
using namespace std;
const int N = 501, mod = 1e9 + 7;
char s[N][N];
int n, m, dp[2][N][N];
vector<pair<int, int> > a[N + N];
int dx[] = {+1, 0}, dy[] = {0, +1};
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] + 1;
    for (int j = 1; j <= m; j++) {
      a[i + j - 1].push_back(make_pair(i, j));
    }
  }
  int k = (n + m) / 2;
  for (auto p : a[k]) {
    for (auto q : a[n + m - k]) {
      int x1, y1, x2, y2;
      tie(x1, y1) = p;
      tie(x2, y2) = q;
      if ((n + m - 1) & 1) {
        dp[k & 1][x1][x2] = (x1 == x2 && y1 == y2);
      } else {
        dp[k & 1][x1][x2] =
            (x1 + 1 == x2 && y1 == y2) || (x1 == x2 && y1 + 1 == y2);
      }
    }
  }
  for (int z = k - 1; z >= 1; z--) {
    for (auto p : a[z]) {
      for (auto q : a[n + m - z]) {
        int x1, y1, x2, y2, res = 0;
        tie(x1, y1) = p;
        tie(x2, y2) = q;
        for (int i = 0; i < 2; i++) {
          for (int j = 0; j < 2; j++) {
            if (s[x1 + dx[i]][y1 + dy[i]] == s[x2 - dx[j]][y2 - dy[j]]) {
              res += dp[(z + 1) & 1][x1 + dx[i]][x2 - dx[j]];
              res %= mod;
            }
          }
        }
        dp[z & 1][x1][x2] = res;
      }
    }
  }
  cout << dp[1][1][n] * (s[1][1] == s[n][m]) << endl;
}
