#include <bits/stdc++.h>
using namespace std;
int N, M;
char A[505][505];
long long DP[2][505][505];
bool r(int x) { return (x >= 1 and x <= N); }
bool c(int x) { return (x >= 1 and x <= M); }
bool isValid(int x1, int y1, int x2, int y2) {
  return (r(x1) and c(y1) and r(x2) and c(y2));
}
long long f(int x1, int y1, int x2, int y2) {
  if (isValid(x1, y1, x2, y2) == false) return 0;
  return DP[x1 & 1][y1][x2];
}
int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) cin >> A[i][j];
  for (int i = N + M; i >= 2; i--) {
    for (int x1 = N; x1 >= 1; x1--) {
      int y1 = i - x1;
      for (int x2 = N; x2 >= 1; x2--) {
        int y2 = N + M - x2 - x1 - y1 + 2;
        if (isValid(x1, y1, x2, y2) == false)
          continue;
        else if (A[x1][y1] != A[x2][y2])
          DP[x1 & 1][y1][x2] = 0;
        else if (abs(x2 - x1) + abs(y2 - y1) <= 1)
          DP[x1 & 1][y1][x2] = 1;
        else if (y1 > y2 or x1 > x2)
          DP[x1 & 1][y1][x2] = 0;
        else {
          DP[x1 & 1][y1][x2] = f(x1 + 1, y1, x2, y2 - 1);
          DP[x1 & 1][y1][x2] %= (int)(1e9 + 7);
          DP[x1 & 1][y1][x2] += f(x1 + 1, y1, x2 - 1, y2);
          DP[x1 & 1][y1][x2] %= (int)(1e9 + 7);
          DP[x1 & 1][y1][x2] += f(x1, y1 + 1, x2, y2 - 1);
          DP[x1 & 1][y1][x2] %= (int)(1e9 + 7);
          DP[x1 & 1][y1][x2] += f(x1, y1 + 1, x2 - 1, y2);
          DP[x1 & 1][y1][x2] %= (int)(1e9 + 7);
        }
      }
    }
  }
  cout << DP[1][1][N] << "\n";
}
