#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int N = 550;
void M(int &x) {
  if (x >= MOD) x -= MOD;
}
int f[2][N][N];
char str[N][N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  if (str[1][1] != str[n][m]) return 0 * printf("0\n");
  f[1][1][n] = 1;
  int tol = (n + m) / 2;
  for (int s = 2; s <= tol; s++) {
    int cur = s & 1;
    int pre = cur ^ 1;
    memset(f[cur], 0, sizeof(f[cur]));
    for (int xa = 1; xa <= s; xa++)
      for (int xb = n; xb >= n - s + 1; xb--) {
        int ya = s + 1 - xa, yb = n + m + 1 - s - xb;
        if (xa > xb || ya > yb) continue;
        if (str[xa][ya] != str[xb][yb]) continue;
        M(f[cur][xa][xb] += f[pre][xa][xb]);
        M(f[cur][xa][xb] += f[pre][xa - 1][xb]);
        M(f[cur][xa][xb] += f[pre][xa][xb + 1]);
        M(f[cur][xa][xb] += f[pre][xa - 1][xb + 1]);
      }
  }
  int cur = tol & 1;
  int ans = 0;
  if ((n + m) % 2 == 1) {
    for (int i = 1; i <= n; i++)
      M(ans += f[cur][i][i]), M(ans += f[cur][i][i + 1]);
  } else {
    for (int i = 1; i <= n; i++) M(ans += f[cur][i][i]);
  }
  printf("%d\n", ans);
  return 0;
}
