#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10;
const int MOD = 1e9 + 7;
char s[N][N];
int _dp[2][N][N], (*d)[N] = _dp[0], (*e)[N] = _dp[1];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  int k = (n + m - 2) / 2;
  int parity = (n + m - 2) % 2;
  for (int i = max(0, k - m + 1); i <= k && i < n; ++i) {
    int j = k - i;
    for (int u = max(0, k - m + 1); u <= k && u < n; ++u) {
      int v = k - u;
      d[i][u] = (s[i][j] == s[n - 1 - u][m - 1 - v] &&
                 abs(n - 1 - u - i) + abs(m - 1 - v - j) == parity);
    }
  }
  for (--k; k >= 0; --k) {
    for (int i = max(0, k - m + 1); i <= k && i < n; ++i) {
      int j = k - i;
      for (int u = max(0, k - m + 1); u <= k && u < n; ++u) {
        int v = k - u;
        if (s[i][j] == s[n - 1 - u][m - 1 - v]) {
          long long sum = 0;
          if (j + 1 < m) {
            if (v + 1 < m) sum += d[i][u];
            if (u + 1 < n) sum += d[i][u + 1];
          }
          if (i + 1 < n) {
            if (v + 1 < m) sum += d[i + 1][u];
            if (u + 1 < n) sum += d[i + 1][u + 1];
          }
          e[i][u] = sum % MOD;
        } else {
          e[i][u] = 0;
        }
      }
    }
    swap(d, e);
  }
  printf("%d\n", d[0][0]);
  return 0;
}
