#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int mod = 1e9 + 7;
int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
char mat[N][N];
int n, m;
int dp[N][N][2];
int f(int i, int j, int ii, int jj) {
  if (ii < 0 or jj < 0 or i >= n or j >= m) return 0;
  if (i == ii and j == jj) return 1;
  if (i + 1 == ii and j == jj) return mat[i][j] == mat[ii][jj];
  if (i == ii and j + 1 == jj) return mat[i][j] == mat[ii][jj];
  int &ans = dp[i][j][ii];
  if (~ans) return ans;
  ans = 0;
  if (mat[i][j] == mat[ii][jj]) {
    ans = add(ans, f(i + 1, j, ii - 1, jj));
    ans = add(ans, f(i + 1, j, ii, jj - 1));
    ans = add(ans, f(i, j + 1, ii - 1, jj));
    ans = add(ans, f(i, j + 1, ii, jj - 1));
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf(" %s", mat[i]);
  int len = n + m - 1;
  for (int i = 0; i < n; i++)
    for (int ii = i; ii < n; ii++) {
      int l = (len - 1) / 2;
      int j = l - i;
      int jj = (len - 1 - l) - ii;
      if (j < 0 or jj < 0) continue;
      if (j >= m or jj >= m) continue;
      if (i == ii and j == jj) dp[i][ii][0] = 1;
      if (i + 1 == ii and j == jj) dp[i][ii][0] = mat[i][j] == mat[ii][jj];
      if (i == ii and j + 1 == jj) dp[i][ii][0] = mat[i][j] == mat[ii][jj];
    }
  int dd = 0;
  for (int lvl = (len - 1) / 2 - 1; lvl >= 0; dd ^= 1, lvl--) {
    for (int i = 0; i < n; i++)
      for (int ii = 0; ii < n; ii++) dp[i][ii][1 - dd] = 0;
    for (int i = 0; i < n; i++)
      for (int ii = i; ii <= n; ii++) {
        int j = lvl - i;
        int jj = (len - 1 - lvl) - ii;
        if (j < 0 or jj < 0) continue;
        if (j >= m or jj >= m) continue;
        int &ans = dp[i][ii][1 - dd];
        if (mat[i][j] == mat[ii][jj]) {
          if (ii - 1 >= 0) ans = add(ans, dp[i + 1][ii - 1][dd]);
          ans = add(ans, dp[i + 1][ii][dd]);
          if (ii - 1 >= 0) ans = add(ans, dp[i][ii - 1][dd]);
          ans = add(ans, dp[i][ii][dd]);
        }
      }
  }
  printf("%d\n", dp[0][n - 1][dd]);
}
