#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
  return (out << "(" << a.first << "; " << a.second << ")");
}
template <typename T1>
ostream &operator<<(ostream &cout, vector<T1> &a) {
  if ((int)a.size() == 0) return (cout << "()");
  cout << "(" << a[0];
  for (int i = 1; i < (int)a.size(); i++) cout << "; " << a[i];
  cout << ")";
  return cout;
}
const int nmax = 1000;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
const long double pi = acos(-1.0);
const long long infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
int n, m, dp[2][nmax][nmax];
string s[nmax];
int main() {
  cin >> n >> m;
  getline(cin, s[0]);
  for (int i = 0; i < n; i++) {
    getline(cin, s[i]);
  }
  if (s[0][0] != s[n - 1][m - 1]) {
    cout << 0 << endl;
    return 0;
  }
  dp[0][0][n - 1] = 1;
  int t = 0;
  for (int i = 0; i < (n + m - 2) / 2; i++) {
    for (int x1 = 0; x1 < n; x1++) {
      for (int x2 = x1; x2 < n; x2++) {
        int y1_dhs = i - x1 + 1;
        int y2 = m - 1 - (i + 1 - (n - 1 - x2));
        if (s[x1][y1_dhs] == s[x2][y2]) {
          if (x1 > 0 && x2 < n - 1) {
            dp[1 - t][x1][x2] =
                (dp[1 - t][x1][x2] + dp[t][x1 - 1][x2 + 1]) % mod;
          }
          if (x1 > 0 && y2 < m - 1) {
            dp[1 - t][x1][x2] = (dp[1 - t][x1][x2] + dp[t][x1 - 1][x2]) % mod;
          }
          if (y1_dhs > 0 && x2 < n - 1) {
            dp[1 - t][x1][x2] = (dp[1 - t][x1][x2] + dp[t][x1][x2 + 1]) % mod;
          }
          if (y1_dhs > 0 && y2 < m - 1) {
            dp[1 - t][x1][x2] = (dp[1 - t][x1][x2] + dp[t][x1][x2]) % mod;
          }
        }
      }
    }
    t = 1 - t;
    for (int x1 = 0; x1 < n; x1++) {
      for (int x2 = 0; x2 < n; x2++) {
        dp[1 - t][x1][x2] = 0;
      }
    }
  }
  long long answer = 0;
  if ((n + m - 2) % 2 == 0) {
    for (int i = 0; i < n; i++) {
      answer = (answer + dp[t][i][i]) % mod;
    }
  } else {
    for (int i = 0; i < n; i++) {
      answer = (answer + dp[t][i][i + 1] + dp[t][i][i]) % mod;
    }
  }
  cout << answer << endl;
}
