#include <bits/stdc++.h>
using namespace std;
const int oo = INT_MAX;
const double pi = acos(-1.0);
int n, m;
const int maxN = 505;
const int mod = 1e9 + 7;
char a[maxN][maxN];
int first[3][maxN][maxN];
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  int dist = (n + m - 2);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  if (a[1][1] != a[n][m]) {
    cout << 0;
    return 0;
  }
  first[0][1][n] = 1;
  for (int step = 0; step <= (dist / 2); step++) {
    memset(first[(step + 1) % 2], 0, sizeof(first[(step + 1) % 2]));
    for (int x1 = 1; x1 <= n; x1++) {
      for (int x2 = n; x2 >= x1; x2--) {
        int y1 = step + 2 - x1;
        int y2 = m - (step - (n - x2));
        if (y1 <= 0 || y1 > m || y2 <= 0) continue;
        if (a[x1][y1] != a[x2][y2]) continue;
        int tmp = first[step % 2][x1][x2];
        if (a[x1][y1 + 1] == a[x2][y2 - 1])
          first[(step + 1) % 2][x1][x2] =
              (first[(step + 1) % 2][x1][x2] + tmp) % mod;
        if (a[x1 + 1][y1] == a[x2][y2 - 1])
          first[(step + 1) % 2][x1 + 1][x2] =
              (first[(step + 1) % 2][x1 + 1][x2] + tmp) % mod;
        if (a[x1][y1 + 1] == a[x2 - 1][y2])
          first[(step + 1) % 2][x1][x2 - 1] =
              (first[(step + 1) % 2][x1][x2 - 1] + tmp) % mod;
        if (a[x1 + 1][y1] == a[x2 - 1][y2])
          first[(step + 1) % 2][x1 + 1][x2 - 1] =
              (first[(step + 1) % 2][x1 + 1][x2 - 1] + tmp) % mod;
      }
    }
  }
  if (dist % 2) {
    long long ans = 0;
    for (int x = 1; x <= n; x++) {
      ans = ((ans + first[(dist / 2) % 2][x][x]) % mod +
             first[(dist / 2) % 2][x][x + 1]) %
            mod;
    }
    cout << ans;
  } else {
    long long ans = 0;
    for (int x = 1; x <= n; x++) {
      ans = (ans + first[(dist / 2) % 2][x][x]) % mod;
    }
    cout << ans << endl;
  }
  return 0;
}
