#include <bits/stdc++.h>
using namespace std;
char a[505][505];
long long c[505][505];
long long d[505][505];
const long long mod = int(1e9) + 7;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  gets(a[0]);
  for (int i = 0; i < n; i++) gets(a[i]);
  if (a[0][0] != a[n - 1][m - 1]) {
    cout << 0;
    return 0;
  }
  c[0][0] = 1;
  int l_c = (n + m - 1) / 2;
  for (int layer = 1; layer < l_c; layer++) {
    for (int i = 0; i <= layer; i++) {
      for (int j = 0; j <= layer; j++) {
        d[i][j] = 0;
        int x1 = i;
        int y1 = layer - i;
        int x2 = n - j - 1;
        int y2 = m - layer - 1 + j;
        if (x1 >= n || y1 >= m || x2 < 0 || y2 < 0) continue;
        if (a[x1][y1] != a[x2][y2]) continue;
        d[i][j] = c[i][j];
        if (i > 0) d[i][j] += c[i - 1][j];
        if (j > 0) d[i][j] += c[i][j - 1];
        if (i > 0 && j > 0) d[i][j] += c[i - 1][j - 1];
        d[i][j] %= mod;
      }
    }
    swap(c, d);
  }
  long long res = 0;
  int layer = l_c - 1;
  for (int i = 0; i <= layer; i++)
    for (int j = 0; j <= layer; j++) {
      int x1 = i;
      int y1 = layer - i;
      int x2 = n - j - 1;
      int y2 = m - layer - 1 + j;
      if (x1 >= n || y1 >= m || x2 < 0 || y2 < 0) continue;
      if (x1 + 1 == x2 && y1 == y2)
        res += c[i][j];
      else if (x1 == x2 && y1 + 1 == y2)
        res += c[i][j];
      else if (x1 + 2 == x2 && y1 == y2)
        res += c[i][j];
      else if (x1 == x2 && y1 + 2 == y2)
        res += c[i][j];
      else if (x1 + 1 == x2 && y1 + 1 == y2)
        res += 2 * c[i][j];
      res %= mod;
    }
  cout << res;
  return 0;
}
