#include <bits/stdc++.h>
using namespace std;
template <class temp>
inline void Mod(temp &a, temp b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
int n, m, l;
char str[505][505];
int dp[2][505][505];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  l = n + m >> 1;
  int ans = 0;
  int cur = 0;
  if (str[1][1] == str[n][m]) dp[cur][0][0] = 1;
  for (int i = 0; i < l; i++) {
    memset(dp[cur ^ 1], 0, sizeof(dp[cur ^ 1]));
    for (int j = max(i + 1 - m, 0); j <= min(i, n - 1); j++)
      for (int k = max(i + 1 - m, 0); k <= min(i, n - 1); k++)
        if (str[j + 1][1 + (i - j)] == str[n - k][m - (i - k)]) {
          int x1 = j + 1, y1 = i - j + 1, x2 = n - k, y2 = m - (i - k);
          int res = dp[cur][j][k];
          if (x1 == x2 && y1 == y2 || x1 == x2 && y1 + 1 == y2 ||
              y1 == y2 && x1 + 1 == x2) {
            Mod(ans, res);
            continue;
          }
          if (str[x1 + 1][y1] == str[x2 - 1][y2])
            Mod(dp[cur ^ 1][j + 1][k + 1], res);
          if (str[x1][y1 + 1] == str[x2 - 1][y2])
            Mod(dp[cur ^ 1][j][k + 1], res);
          if (str[x1 + 1][y1] == str[x2][y2 - 1])
            Mod(dp[cur ^ 1][j + 1][k], res);
          if (str[x1][y1 + 1] == str[x2][y2 - 1]) Mod(dp[cur ^ 1][j][k], res);
        }
    cur ^= 1;
  }
  printf("%d\n", ans);
}
