#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, l, sum = 0, flag = 0, t, ans = 0, cnt = 1, m;
int dp[505][505][251];
string s[505];
long long f(int first, int xx, int moves) {
  int second, yy;
  second = moves - first;
  yy = m - 1 - (moves - (n - 1 - xx));
  if (xx < first || yy < second || s[first][second] != s[xx][yy]) return 0;
  if ((first == xx && second == yy) ||
      (abs(first - xx) + abs(second - yy) == 1))
    return 1;
  if (dp[first][xx][moves] != -1) return dp[first][xx][moves];
  long long ans = 0;
  ans = (ans + f(first + 1, xx - 1, moves + 1)) % 1000000007;
  ans = (ans + f(first + 1, xx, moves + 1)) % 1000000007;
  ans = (ans + f(first, xx - 1, moves + 1)) % 1000000007;
  ans = (ans + f(first, xx, moves + 1)) % 1000000007;
  return dp[first][xx][moves] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  cout << f(0, n - 1, 0) << '\n';
  return 0;
}
