#include <bits/stdc++.h>
using namespace std;
const int N = 510, MOD = 1e9 + 7;
int n, m;
char s[N][N];
int dp[2][N][N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  for (int x1 = n; x1 >= 1; x1--) {
    bool xx1 = x1 & 1;
    for (int y1 = m; y1 >= 1; y1--) {
      for (int x2 = 1; x2 <= n; x2++) {
        int y2 = n - x2 + m - x1 - y1 + 2;
        if (x1 > x2 || y1 > y2 || s[x1][y1] != s[x2][y2]) {
          dp[xx1][y1][x2] = 0;
          continue;
        }
        int ans = 0;
        if (x1 == x2 && y1 == y2) {
          ans = 1;
        } else if (x1 == x2 && y1 + 1 == y2) {
          ans = 1;
        } else if (x1 + 1 == x2 && y1 == y2) {
          ans = 1;
        } else {
          ans = (ans + dp[!xx1][y1][x2 - 1]) % MOD;
          ans = (ans + dp[!xx1][y1][x2]) % MOD;
          ans = (ans + dp[xx1][y1 + 1][x2 - 1]) % MOD;
          ans = (ans + dp[xx1][y1 + 1][x2]) % MOD;
        }
        dp[xx1][y1][x2] = ans;
      }
    }
  }
  printf("%d\n", dp[1][1][n]);
  return 0;
}
