#include <bits/stdc++.h>
using namespace std;
const int Maxn = 502;
const int Big_prime = 1e9 + 7;
char ch[Maxn][Maxn];
long long f[2][Maxn][Maxn];
int n, m, i, j, k, mid, front[2], rear[2], Right, Left, sum, rest, u, v;
void cul_second(int k, int i) {
  Left = rest - m;
  front[1] = i < Left ? Left : i;
  Right = rest - k + i;
  rear[1] = Right > n ? n : Right;
}
void cul_first(int k) {
  front[0] = k - m < 0 ? 0 : (k - m);
  rear[0] = k < n ? k : n;
}
void Init() {
  sum = n + m;
  mid = sum / 2;
  cul_first(mid);
  rest = sum - mid;
  for (i = front[0]; i <= rear[0]; i++) {
    cul_second(mid, i);
    for (j = front[1]; j <= rear[1]; j++)
      if (ch[i][mid - i] == ch[j][rest - j]) ++f[0][i][j];
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", ch[i]);
  --n;
  --m;
  Init();
  u = 0;
  for (k = mid - 1; k >= 0; k--) {
    v = u xor 1;
    cul_first(k);
    rest = sum - k;
    memset(f[v], 0, sizeof(f[v]));
    for (i = front[0]; i <= rear[0]; i++) {
      cul_second(k, i);
      for (j = front[1]; j <= rear[1]; j++)
        if (ch[i][k - i] == ch[j][rest - j]) {
          f[v][i][j] = f[u][i][j] + f[u][i + 1][j];
          if (j > 0) f[v][i][j] += f[u][i][j - 1] + f[u][i + 1][j - 1];
          f[v][i][j] = f[v][i][j] % Big_prime;
        }
    }
    u = v;
  }
  printf("%I64d\n", f[u][0][n]);
  return 0;
}
