#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long linf = (long long)1e17;
const long double eps = 1e-9;
const double pi = acos(-1.0);
const int MAXN = 555;
const int MOD = (int)1e9 + 7;
int f[2][MAXN][MAXN], n, m;
char s[MAXN][MAXN];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int k = 0; k < n; ++k)
    for (int i = n - 1; i >= 0; --i)
      for (int j = m - 1; j >= 0; --j) {
        int &p = f[k & 1][i][j] = 0, l = n + m - 2 - i - j - k;
        if (i <= k && j <= l && s[i][j] == s[k][l] &&
            !(p = abs(i - k) + abs(j - l) <= 1))
          for (int c1 = 0; c1 < 2; ++c1)
            for (int c2 = 0; c2 < 2; ++c2)
              p = (p + f[(i - c2) & 1][i + !c1][j + c1]) % MOD;
      }
  cout << f[~n & 1][0][0] << endl;
  return 0;
}
