#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, -1, 0, 0}, dy[]{1, 0, 1, 0}, f[2][1000][1000];
char s[1000][1000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
  if (s[1][1] != s[n][m]) {
    puts("0");
    return 0;
  }
  f[1][1][n] = 1;
  int now = 1;
  for (int st = 2; st <= (n + m) >> 1; ++st) {
    now ^= 1;
    memset(f[now], 0, sizeof(f[now]));
    for (int i = 1; i <= min(st, n); ++i)
      for (int k = n; k >= max(n - st, i); --k) {
        int j = st - i + 1, p = m - (st - (n - k)) + 1;
        if (s[i][j] == s[k][p])
          for (int t = 0; t < 4; ++t)
            f[now][i][k] =
                (f[now][i][k] + f[now ^ 1][i + dx[t]][k + dy[t]]) % 1000000007;
      }
  }
  long long ans = 0;
  if ((n + m) & 1)
    for (int i = 1; i <= n; ++i)
      ans = (ans + f[now][i][i] + f[now][i][i + 1]) % 1000000007;
  else
    for (int i = 1; i <= n; ++i) ans = (ans + f[now][i][i]) % 1000000007;
  printf("%d", ans);
}
