#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 5;
const int mod = 1e9 + 7;
long long dp[2][maxn][maxn];
char maze[maxn][maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", maze[i]);
  }
  if (maze[0][0] != maze[n - 1][m - 1]) {
    puts("0");
  } else {
    dp[0][0][n - 1] = 1;
    int step = (n + m - 2) / 2;
    long long ans = 0;
    for (int s = 0; s <= step; ++s) {
      for (int i = 0; i < min(n, s + 1); ++i) {
        int j = s - i;
        if (j >= m) continue;
        for (int k = n - 1; k >= max(i, n - 1 - s); --k) {
          int l = m - 1 - (s - (n - 1 - k));
          if (l < 0) continue;
          if (maze[i][j] == maze[k][l]) {
            if (i + 1 <= k - 1) {
              dp[s & 1 ^ 1][i + 1][k - 1] =
                  (dp[s & 1 ^ 1][i + 1][k - 1] + dp[s & 1][i][k]) % mod;
            }
            if (j + 1 <= l - 1) {
              dp[s & 1 ^ 1][i][k] =
                  (dp[s & 1 ^ 1][i][k] + dp[s & 1][i][k]) % mod;
            }
            if (i + 1 <= k && j + 1 <= l) {
              dp[s & 1 ^ 1][i + 1][k] =
                  (dp[s & 1 ^ 1][i + 1][k] + dp[s & 1][i][k]) % mod;
              dp[s & 1 ^ 1][i][k - 1] =
                  (dp[s & 1 ^ 1][i][k - 1] + dp[s & 1][i][k]) % mod;
            }
            if (s == step) {
              ans = (ans + dp[s & 1][i][k]) % mod;
            }
          }
          dp[s & 1][i][k] = 0;
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
