#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 520;
long long n, m, f[2][N][N], now = 0, ans;
char ch[N][N];
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) scanf("%s", ch[i] + 1);
  if (ch[1][1] != ch[n][m]) return puts("0"), 0;
  f[0][1][n] = 1;
  for (long long i = 1; i <= (n + m) / 2; i++) {
    now ^= 1;
    memset(f[now], 0, sizeof f[now]);
    for (long long j = 1; j <= i + 1; j++) {
      for (long long a = n; a >= n - i; a--) {
        long long k = i + 2 - j, b = n + m - i - a;
        if (j > a || k > b) continue;
        if (j < 1 || j > n || k < 1 || k > m) continue;
        if (ch[j][k] == ch[a][b]) {
          f[now][j][a] = (f[now][j][a] + f[now ^ 1][j][a]) % mod;
          f[now][j][a] = (f[now][j][a] + f[now ^ 1][j - 1][a]) % mod;
          f[now][j][a] = (f[now][j][a] + f[now ^ 1][j][a + 1]) % mod;
          f[now][j][a] = (f[now][j][a] + f[now ^ 1][j - 1][a + 1]) % mod;
        }
      }
    }
  }
  now ^= 1;
  if ((n + m + 1) % 2 == 1) {
    for (long long i = 1; i <= n; i++) ans = (ans + f[now][i][i]) % mod;
  } else {
    for (long long i = 1; i <= n; i++) {
      ans = (ans + f[now][i][i] + f[now][i][i + 1]) % mod;
    }
  }
  cout << ans;
  return 0;
}
