#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
const int MOD = 1e9 + 7;
long long dp[2][maxn][maxn];
int N, M;
char s[maxn][maxn];
void add(long long &x, long long y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%s", s[i] + 1);
  dp[0][1][N] = (s[1][1] == s[N][M]);
  int cur = 0;
  for (int step = 1; step <= (M + N - 2) / 2; step++) {
    cur ^= 1;
    for (int i = 0; i <= N; i++)
      for (int j = 1; j <= N; j++) dp[cur][i][j] = 0;
    for (int x1 = 1; x1 <= N && x1 - 1 <= step; x1++) {
      for (int x2 = N; x2 >= 1 && N - x2 <= step; x2--) {
        int y1 = 1 + step - (x1 - 1);
        int y2 = M - (step - (N - x2));
        if (s[x1][y1] != s[x2][y2]) continue;
        add(dp[cur][x1][x2], dp[cur ^ 1][x1][x2]);
        add(dp[cur][x1][x2], dp[cur ^ 1][x1][x2 + 1]);
        add(dp[cur][x1][x2], dp[cur ^ 1][x1 - 1][x2]);
        add(dp[cur][x1][x2], dp[cur ^ 1][x1 - 1][x2 + 1]);
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    add(ans, dp[cur][i][i]);
  }
  if ((N + M) % 2) {
    for (int i = 1; i < N; i++) add(ans, dp[cur][i][i + 1]);
  }
  printf("%d\n", ans);
  return 0;
}
