#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[501][501];
int better[501][501][251];
long long MOD = 1000000007;
long long find(int r, int c, int x, int y) {
  if (r > n || c > m || x < 1 || y < 1) return 0;
  if (a[r][c] != a[x][y]) return 0;
  if ((x < r) || (y < c)) return 0;
  if (abs(r - x + c - y) <= 1) return 1;
  if (better[x - r][y - c][(y + c - x + r) / 2] != -1)
    return better[x - r][y - c][(y + c - x + r) / 2];
  long long ansx = 0;
  (ansx += find(r + 1, c, x, y - 1)) %= MOD;
  (ansx += find(r + 1, c, x - 1, y)) %= MOD;
  (ansx += find(r, c + 1, x, y - 1)) %= MOD;
  (ansx += find(r, c + 1, x - 1, y)) %= MOD;
  return better[x - r][y - c][(y + c - x + r) / 2] = ansx % MOD;
}
int main() {
  memset(a, 0, sizeof(a));
  memset(better, -1, sizeof(better));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    string xx;
    cin >> xx;
    for (int j = 1; j <= m; j++) a[i][j] = xx[j - 1];
  }
  cout << find(1, 1, n, m) % MOD;
  return 0;
}
