#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, m;
int dp[500][250][500];
string s[500];
int bkt(int x, int v, int lin) {
  int y = v - x, col = n + m - 2 - lin - 2 * v, sol = 0;
  if (lin < 0 || col < 0) return 0;
  if (lin == 0 && col == 0) return 1;
  if (s[y][x] != s[y + col][x + lin]) return 0;
  if (lin + col == 1) return 1;
  if (dp[x][v][lin] != -1) return dp[x][v][lin];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++)
      sol = (sol + bkt(x + i, v + 1, lin - i - j)) % MOD;
  }
  dp[x][v][lin] = sol;
  return sol;
}
int main() {
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) cin >> s[i];
  cout << bkt(0, 0, m - 1);
  return 0;
}
