#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
char s[555][555];
int dp[2][500][500];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void ADD(int& x, int v) {
  x += v;
  if (x >= MOD) x -= MOD;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); ++i) scanf("%s", (s[i]));
  if (s[0][0] != s[n - 1][m - 1]) return 0 * puts("0");
  int L = 0, R = n + m - 2;
  dp[0][0][n - 1] = 1;
  int now = 0, nxt = 1;
  while (L <= R) {
    if (L + 1 == R) {
      int an = 0;
      for (int i = 0; i < (n); ++i) {
        ADD(an, dp[now][i][i]);
        if (i + 1 < n) {
          ADD(an, dp[now][i][i + 1]);
        }
      }
      cout << an << endl;
      return 0;
    }
    if (L == R) {
      int an = 0;
      for (int i = 0; i < (n); ++i) ADD(an, dp[now][i][i]);
      cout << an << endl;
      return 0;
    }
    memset((dp[nxt]), 0, sizeof((dp[nxt])));
    for (int i = 0; i < (n); ++i) {
      int x1 = i, y1 = L - i;
      for (int j = (i); j < (n); ++j) {
        int x2 = j, y2 = R - j;
        for (int k1 = 0; k1 < (2); ++k1) {
          int nx1 = x1 + dx[k1];
          int ny1 = y1 + dy[k1];
          for (int k2 = (2); k2 < (4); ++k2) {
            int nx2 = x2 + dx[k2];
            int ny2 = y2 + dy[k2];
            if (nx1 > nx2 || ny1 > ny2 || s[nx1][ny1] != s[nx2][ny2]) continue;
            ADD(dp[nxt][nx1][nx2], dp[now][i][j]);
          }
        }
      }
    }
    L++;
    R--;
    swap(now, nxt);
  }
  return 0;
}
