#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int M = 4e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
char s[N][N];
long long dp[2][N][N];
int dis(int i, int j, int p, int k) {
  if (p < i || k < j) return -1;
  return p - i + k - j;
}
void update(long long &x, long long y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
bool ck(pair<int, int> a, pair<int, int> b) {
  return a.first <= b.first && a.second <= b.second;
}
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  if (s[1][1] != s[n][m]) return 0 * printf("0\n");
  int cur = 0;
  dp[cur][1][n] = 1;
  int len = dis(1, 1, n, m) + 1;
  int r = (len + 1) / 2 - 1;
  for (int i = 1; i <= r; i++) {
    cur ^= 1;
    memset(dp[cur], 0, sizeof(dp[cur]));
    for (int p = 1; p <= 1 + i; p++)
      for (int t = n - i; t <= n; t++) {
        int y1 = i + 2 - p;
        int y2 = n + m - t - i;
        if (!ck(make_pair(p, y1), make_pair(t, y2))) continue;
        if (s[p][y1] != s[t][y2]) continue;
        update(dp[cur][p][t], dp[cur ^ 1][p][t]);
        update(dp[cur][p][t], dp[cur ^ 1][p - 1][t]);
        update(dp[cur][p][t], dp[cur ^ 1][p][t + 1]);
        update(dp[cur][p][t], dp[cur ^ 1][p - 1][t + 1]);
      }
  }
  long long ans = 0;
  if (len & 1) {
    for (int i = 1; i <= n; i++) update(ans, dp[cur][i][i]);
  } else {
    for (int i = 1; i <= n; i++)
      update(ans, dp[cur][i][i]), update(ans, dp[cur][i][i + 1]);
  }
  printf("%lld\n", ans);
  return 0;
}
