#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int N = 501;
int dp[502][252][502];
string s[N];
int n, m;
int go(int x, int y, int vx) {
  if (dp[x][y][vx] != -1) return dp[x][y][vx];
  int vy = -x - y + (n - 1 - vx) - 1 + m;
  if (x < 0 || x >= n || y < 0 || y >= m) return 0;
  if (x > vx || y > vy || s[x][y] != s[vx][vy]) return 0;
  if (x == vx && y == vy) return 1;
  if (x == vx && y == vy - 1) return dp[x][y][vx] = (s[x][y] == s[vx][vy]);
  if (y == vy && x == vx - 1) return dp[x][y][vx] = (s[x][y] == s[vx][vy]);
  dp[x][y][vx] =
      (((go(x + 1, y, vx) + go(x + 1, y, vx - 1)) % Mod + go(x, y + 1, vx)) %
           Mod +
       go(x, y + 1, vx - 1)) %
      Mod;
  return dp[x][y][vx];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < 502; i++)
    for (int j = 0; j < 252; j++)
      for (int k = 0; k < 502; k++) dp[i][j][k] = -1;
  cout << go(0, 0, n - 1) << endl;
}
