#include <bits/stdc++.h>
using namespace std;
char s[502][502];
long long dp[2][502][502];
int n, m;
long long ans = 0;
long long MOD = 1000000007;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  int t = n + m + 2;
  dp[0][1][n] = 1;
  for (int sum = 2; sum <= t / 2; sum++) {
    int r = t - sum;
    memset(dp[1], 0, sizeof(dp[1]));
    for (int y1 = 1; y1 <= n; y1++) {
      for (int y2 = y1; y2 <= n; y2++) {
        int x1 = sum - y1;
        int x2 = r - y2;
        if (y1 + y2 + x1 + x2 > t) break;
        if (x1 < 1 || x1 > m || x2 < 1 || x2 > m || x1 > x2) continue;
        if (s[y1][x1] != s[y2][x2])
          dp[1][y1][y2] = 0;
        else
          dp[1][y1][y2] = (dp[0][y1 - 1][y2] + dp[0][y1][y2] +
                           dp[0][y1][y2 + 1] + dp[0][y1 - 1][y2 + 1]) %
                          MOD;
      }
    }
    for (int y = 1; y <= n; y++)
      for (int x = 1; x <= n; x++) dp[0][y][x] = dp[1][y][x];
  }
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) ans += dp[0][i][j], ans %= MOD;
  printf("%lld", ans);
  return 0;
}
