#include <bits/stdc++.h>
char s[510][510];
long long f[2][510][510] = {0};
const int MOD = 1000000007;
bool judge(int x1, int y1, int x2, int y2) {
  return x1 == x2 && y1 == y2 || x1 == x2 && y1 + 1 == y2 ||
         x1 + 1 == x2 && y1 == y2;
}
int main() {
  long long n, m, tot, ans = 0;
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  tot = n + m - 1;
  f[0][0][0] = 1;
  for (int k = 1; k <= tot; k++) {
    for (int i = 1; i <= n && i <= k; i++)
      for (int j = 1 + k - m >= 1 ? 1 + k - m : 1; j <= n && j <= k; j++)
        if (s[i][k - i + 1] == s[n - j + 1][m - (k - j + 1) + 1]) {
          long long &t = f[k & 1][i][j];
          t = (t + f[k & 1 ^ 1][i - 1][j]) % MOD;
          t = (t + f[k & 1 ^ 1][i - 1][j - 1]) % MOD;
          t = (t + f[k & 1 ^ 1][i][j]) % MOD;
          t = (t + f[k & 1 ^ 1][i][j - 1]) % MOD;
          if (judge(i, k - i + 1, n - j + 1, m - (k - j + 1) + 1))
            ans = (ans + t) % MOD;
        }
    memset(f[k & 1 ^ 1], 0, sizeof(f[k & 1 ^ 1]));
  }
  printf("%lld\n", ans);
  return 0;
}
