#include <bits/stdc++.h>
using namespace std;
char input[500][500];
int output1[500][500];
int output2[500][500];
int N, M;
void read_help(int M, int N, int p) {
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> input[(1 - p) * i + p * j][(1 - p) * j + p * i];
    }
  }
}
void read_input() {
  cin >> M >> N;
  if (M > N) {
    swap(M, N);
    read_help(N, M, 1);
    return;
  }
  read_help(M, N, 0);
}
int to_diag_num(int k, int j) {
  if (k + j >= M - 1 && k + j <= N - 1) {
    return k;
  }
  if (k + j < M - 1) {
    return j;
  }
  return M - k - 1;
}
int solve() {
  int L = (M + N - 2) >> 1;
  int* o1 = &output1[0][0];
  int* o2 = &output2[0][0];
  for (int i = L; i >= 0; --i) {
    swap(o1, o2);
    fill(o2, o2 + 500 * 500, 0);
    int k = (i < M - 1 ? i : M - 1);
    int j = (i < M - 1 ? 0 : i - M + 1);
    for (; k >= 0; --k, ++j) {
      int j1 = (N - i - 1 < j) ? j : N - i - 1;
      int k1 = (N - i - 1 < j) ? M - 1 - (j - N + i + 1) : M - 1;
      for (; k1 >= k && j1 <= N - 1; ++j1, --k1) {
        if (input[k][j] == input[k1][j1]) {
          int cur1 = to_diag_num(k, j);
          int cur2 = to_diag_num(k1, j1);
          int t1 = to_diag_num(k, j + 1);
          int t2 = to_diag_num(k + 1, j);
          int t3 = to_diag_num(k1 - 1, j1);
          int t4 = to_diag_num(k1, j1 - 1);
          if ((k1 == k && j1 - j <= 1) || (k1 - k <= 1 && j1 == j)) {
            o2[500 * cur1 + cur2] = 1;
          } else {
            if (k1 - k > 1) {
              o2[500 * cur1 + cur2] =
                  (o2[500 * cur1 + cur2] + o1[500 * t2 + t3]) % 1000000007;
            }
            if (j1 - j > 1) {
              o2[500 * cur1 + cur2] =
                  (o2[500 * cur1 + cur2] + o1[500 * t1 + t4]) % 1000000007;
            }
            if (k1 - k > 0 && j1 - j > 0) {
              o2[500 * cur1 + cur2] =
                  (o2[500 * cur1 + cur2] + o1[500 * t1 + t3]) % 1000000007;
              o2[500 * cur1 + cur2] =
                  (o2[500 * cur1 + cur2] + o1[500 * t2 + t4]) % 1000000007;
            }
          }
        }
      }
    }
  }
  return o2[0];
}
int main() {
  read_input();
  cout << solve() << '\n';
  return 0;
}
