#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int maxm = 11;
const int maxd = 21;
const int mod = 1e9 + 7;
int n, m;
char s[maxn][maxn];
int dp[2][maxn][maxn];
int main() {
  int i, j;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%s", s[i] + 1);
    }
    int pos = 1;
    memset(dp, 0, sizeof(dp));
    dp[pos][1][n] = (s[1][1] == s[n][m]);
    int lim = (m + n) >> 1;
    for (int step = 1; step < lim; step++) {
      pos ^= 1;
      memset(dp[pos], 0, sizeof(dp[pos]));
      for (i = 1; i <= n && i <= step + 1; i++) {
        for (j = n; j > 0 && (n - j) <= step; j--) {
          int x1 = i;
          int y1 = step - i + 1 + 1;
          int x2 = j;
          int y2 = m - step + n - j;
          if (s[x1][y1] != s[x2][y2]) continue;
          dp[pos][i][j] += dp[pos ^ 1][i - 1][j + 1];
          dp[pos][i][j] %= mod;
          dp[pos][i][j] += dp[pos ^ 1][i - 1][j];
          dp[pos][i][j] %= mod;
          dp[pos][i][j] += dp[pos ^ 1][i][j];
          dp[pos][i][j] %= mod;
          dp[pos][i][j] += dp[pos ^ 1][i][j + 1];
          dp[pos][i][j] %= mod;
        }
      }
    }
    int ans = 0;
    for (i = 1; i <= n; i++) {
      ans += dp[pos][i][i];
      ans %= mod;
    }
    if ((m + n) & 1) {
      for (i = 1; i < n; i++) {
        ans += dp[pos][i][i + 1];
        ans %= mod;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
