#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 1228;
char a[N][N];
long long d, x, y, o, _x, _y, i, j, n, m, dp[2][N][N], k;
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  d = n + m - 2;
  if (a[0][0] == a[n - 1][m - 1]) dp[0][0][n - 1] = 1;
  for (i = 0; i < d / 2; i++) {
    for (x = 0; x < n; x++)
      for (_x = 0; _x < n; _x++)
        if (dp[0][x][_x]) {
          y = i - x, _y = m - (i - (n - _x - 1)) - 1;
          if (x + 1 <= _x - 1 && a[x + 1][y] == a[_x - 1][_y])
            dp[1][x + 1][_x - 1] += dp[0][x][_x];
          if (x + 1 <= _x && y <= _y - 1 && a[x + 1][y] == a[_x][_y - 1])
            dp[1][x + 1][_x] += dp[0][x][_x];
          if (x <= _x - 1 && y + 1 <= _y && a[x][y + 1] == a[_x - 1][_y])
            dp[1][x][_x - 1] += dp[0][x][_x];
          if (y + 1 <= _y - 1 && a[x][y + 1] == a[_x][_y - 1])
            dp[1][x][_x] += dp[0][x][_x];
        }
    for (x = 0; x < n; x++)
      for (y = 0; y < n; y++)
        swap(dp[0][x][y], dp[1][x][y]), dp[0][x][y] %= 1000000007,
            dp[1][x][y] = 0;
  }
  for (x = 0; x < n; x++)
    for (_x = 0; _x < n; _x++) o += dp[0][x][_x], o %= 1000000007;
  cout << o << "\n";
}
