#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int n, m;
char s[510][510];
int dp[2][510][510];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  for (int t = ((m + n) >> 1); t >= 0; t--) {
    for (int x1 = 0; x1 < n; x1++) {
      for (int x2 = 0; x2 < n; x2++) {
        int y1 = t - x1, y2 = m + n - 2 - t - x2;
        if (y1 < 0 || y1 >= m || y2 < 0 || y2 >= m) continue;
        if (x1 > x2 || y1 > y2 || s[x1][y1] != s[x2][y2]) {
          dp[t & 1][x1][x2] = 0;
          continue;
        }
        if (fabs(x1 - x2) + fabs(y1 - y2) <= 1) {
          dp[t & 1][x1][x2] = 1;
          continue;
        }
        dp[t & 1][x1][x2] =
            ((long long)dp[(t + 1) & 1][x1][x2] + dp[(t + 1) & 1][x1 + 1][x2] +
             dp[(t + 1) & 1][x1][x2 - 1] + dp[(t + 1) & 1][x1 + 1][x2 - 1]) %
            1000000007;
      }
    }
  }
  printf("%d\n", dp[0][0][n - 1]);
  return 0;
}
