#include <bits/stdc++.h>
char map[510][501];
const int mod = 1e9 + 7;
int f[2][502][502];
inline bool judge(int x1, int y1, int x2, int y2) {
  if (x1 == x2 && y1 == y2) return true;
  if (x1 + 1 == x2 && y1 == y2) return true;
  if (x1 == x2 && y1 + 1 == y2) return true;
  return false;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  char t;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      t = getchar();
      while (t == ' ' || t == '\n') t = getchar();
      map[i][j] = t;
    }
  if (map[1][1] == map[n][m]) f[1][1][n] = 1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      for (int p = n; p >= 1; p--) {
        if (i + j - 1 > n + m - i - j + 1) continue;
        int q = n + m - p - i - j + 2;
        if (map[i][j] == map[p][q]) {
          f[i & 1][j][p] = (f[i & 1][j][p] + f[(i - 1) & 1][j][p + 1]) % mod;
          f[i & 1][j][p] = (f[i & 1][j][p] + f[(i - 1) & 1][j][p]) % mod;
          f[i & 1][j][p] = (f[i & 1][j][p] + f[i & 1][j - 1][p + 1]) % mod;
          f[i & 1][j][p] = (f[i & 1][j][p] + f[i & 1][j - 1][p]) % mod;
          if (judge(i, j, p, q)) ans = (ans + f[i & 1][j][p]) % mod;
        }
      }
    memset(f[(i - 1) & 1], 0, sizeof(f[(i - 1) & 1]));
  }
  printf("%d\n", (int)ans);
  return 0;
}
