#include <bits/stdc++.h>
using namespace std;
const long long INFLL = 2 * (long long)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
const double PI = atan(1) * 4;
const double EPS = 1e-9;
const int SEED = 1e3 + 7;
const int MOD = 1e9 + 7;
const int NMAX = 1000 + 5;
int n, m;
char mat[NMAX][NMAX];
int dp[2][NMAX][NMAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> mat[i][j];
  for (int x1 = n; x1 >= 1; x1--) {
    for (int y1 = m; y1 >= 1; y1--) {
      for (int x2 = 1; x2 <= n; x2++) {
        int y2 = n + m - x1 - y1 - x2 + 2;
        if (y2 > m || mat[x1][y1] != mat[x2][y2] || x1 > x2 || y1 > y2)
          continue;
        if (mat[x1][y1] == mat[x2][y2] && (x2 - x1 + y2 - y1) <= 1) {
          dp[x1 & 1][y1][x2]++;
          dp[x1 & 1][y1][x2] %= MOD;
          if (x2 - x1 + y2 - y1 <= 1) continue;
        }
        dp[x1 & 1][y1][x2] += dp[(x1 & 1) ^ 1][y1][x2 - 1];
        dp[x1 & 1][y1][x2] %= MOD;
        dp[x1 & 1][y1][x2] += dp[(x1 & 1) ^ 1][y1][x2];
        dp[x1 & 1][y1][x2] %= MOD;
        dp[x1 & 1][y1][x2] += dp[x1 & 1][y1 + 1][x2 - 1];
        dp[x1 & 1][y1][x2] %= MOD;
        dp[x1 & 1][y1][x2] += dp[x1 & 1][y1 + 1][x2];
        dp[x1 & 1][y1][x2] %= MOD;
      }
    }
    for (int y1 = 1; y1 <= m; y1++)
      for (int x2 = 1; x2 <= n; x2++) dp[(x1 & 1) ^ 1][y1][x2] = 0;
  }
  cout << dp[1][1][n];
  return 0;
}
