#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 504;
const int maxm = maxn / 2;
int n, m;
string g[maxn];
const int mod = 1e9 + 7;
int dp[maxn][maxn][maxm];
int go(int x1, int x2, int moves) {
  int y1 = moves - x1;
  int y2 = n + m - 2 - x2 - moves;
  if (x1 > x2) return 0;
  if (y1 > y2) return 0;
  if (g[x1][y1] != g[x2][y2]) return 0;
  if (x1 == x2 && y2 - y1 <= 1) return 1;
  if (y1 == y2 && x2 - x1 <= 1) return 1;
  int &ans = dp[x1][x2][moves];
  if (ans != -1) return ans;
  ans = 0;
  ans += go(x1 + 1, x2 - 1, moves + 1);
  ans %= mod;
  ans += go(x1, x2, moves + 1);
  ans %= mod;
  ans += go(x1 + 1, x2, moves + 1);
  ans %= mod;
  ans += go(x1, x2 - 1, moves + 1);
  ans %= mod;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }
  memset(dp, -1, sizeof dp);
  int ans = go(0, n - 1, 0);
  cout << ans << endl;
  return 0;
}
