#include <bits/stdc++.h>
using namespace std;
int n, m, ans, old[505][505], dp[505][505];
char grid[505][505];
bool valid(int a, int b) { return a >= 0 && a < n && b >= 0 && b < m; }
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (n > m)
        cin >> grid[j][i];
      else
        cin >> grid[i][j];
    }
  }
  if (n > m) swap(m, n);
  for (int i = 0; i < (m + n) / 2; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= m; k++) {
        int temp = 0, x1 = j, y1 = i - j, x2 = n - (i - k) - 1, y2 = m - k - 1;
        if (!valid(x1, y1) || !valid(x2, y2)) continue;
        if (i == 0)
          dp[j][k] = 1;
        else if (grid[x1][y1] == grid[x2][y2]) {
          for (int a = 0; a < 2; a++) {
            for (int b = 0; b < 2; b++) {
              int tj = j - a, tk = k - b;
              if (!valid(tj, i - 1 - tj) ||
                  !valid(n - (i - 1 - tk) - 1, m - tk - 1))
                continue;
              dp[j][k] = (dp[j][k] + old[tj][tk]) % 1000000007;
            }
          }
        }
      }
    }
    for (int i = 0; i < 505; i++) {
      for (int j = 0; j < 505; j++) {
        old[i][j] = dp[i][j];
        dp[i][j] = 0;
      }
    }
  }
  if ((m + n) % 2 == 0) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m; k++) {
        int i = (m + n) / 2 - 1;
        int temp = 0, x1 = j, y1 = i - j, x2 = n - (i - k) - 1, y2 = m - k - 1;
        if (x1 == x2 && y1 == y2) ans = (ans + old[j][k]) % 1000000007;
      }
    }
  } else {
    for (int j = 0; j < max(m, n); j++) {
      for (int k = 0; k < max(m, n); k++) {
        int i = (m + n) / 2 - 1;
        int temp = 0, x1 = j, y1 = i - j, x2 = n - (i - k) - 1, y2 = m - k - 1;
        if (!valid(x1, y1) || !valid(x2, y2)) continue;
        if (abs(x1 - x2) + abs(y1 - y2) == 1)
          ans = (ans + old[j][k]) % 1000000007;
      }
    }
  }
  if (grid[0][0] != grid[n - 1][m - 1])
    cout << 0;
  else
    cout << ans << "\n";
}
