#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
const int maxm = 505;
const int mod = 1e9 + 7;
char s[maxn][maxm];
int dp[2][maxn][maxm];
void add(int &x, int y) {
  if ((x += y) >= mod) x -= mod;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  int t = 0;
  memset(dp[t], 0, sizeof(dp[t]));
  dp[t][1][n] = s[n][m] == s[1][1];
  int step = (n + m - 2) / 2;
  for (int i = 1; i <= step; i++) {
    memset(dp[!t], 0, sizeof(dp[!t]));
    for (int x1 = 1; x1 <= i + 1; x1++) {
      for (int x2 = n; x2 >= n - i; x2--) {
        int y1 = i + 2 - x1;
        int y2 = n + m - i - x2;
        if (s[x1][y1] != s[x2][y2]) continue;
        add(dp[!t][x1][x2], dp[t][x1][x2]);
        add(dp[!t][x1][x2], dp[t][x1][x2 + 1]);
        add(dp[!t][x1][x2], dp[t][x1 - 1][x2]);
        add(dp[!t][x1][x2], dp[t][x1 - 1][x2 + 1]);
      }
    }
    t = !t;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    add(ans, dp[t][i][i]);
    if (n + m & 1) add(ans, dp[t][i][i + 1]);
  }
  printf("%d\n", ans);
  return 0;
}
