#include <bits/stdc++.h>
using namespace std;
int dp[501][501][250];
string arr[501];
int n, m;
int solve(int a, int b, int x, int y) {
  if (x < a || y < b) return 0;
  if (arr[a][b] != arr[x][y]) return 0;
  if (abs(a - x) + abs(y - b) <= 1) {
    return 1;
  }
  int &ret = dp[abs(x - a)][abs(y - b)][abs(a + x + y - b) / 2];
  if (ret != -1) return ret;
  ret = 0;
  ret += solve(a + 1, b, x - 1, y);
  ret %= 1000000007;
  ret += solve(a + 1, b, x, y - 1);
  ret %= 1000000007;
  ret += solve(a, b + 1, x - 1, y);
  ret %= 1000000007;
  ret += solve(a, b + 1, x, y - 1);
  ret %= 1000000007;
  return ret;
}
int main() {
  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) cin >> arr[i];
  cout << solve(0, 0, n - 1, m - 1) << endl;
}
