#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int MOD = 1E9 + 7;
const int N = 5E2 + 7;
int n, m;
char st[N][N];
int dp[2][N][N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", &st[i][1]);
  }
  dp[0][1][n] = st[1][1] == st[n][m];
  int cur = 0;
  int mx = (m + n - 2) / 2;
  for (int step = 1; step <= mx; step++) {
    cur = cur ^ 1;
    for (int i = 1; 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 hust111qqz = 1 + step - (x1 - 1);
        int y2 = m - step + (n - x2);
        if (st[x1][hust111qqz] == st[x2][y2]) {
          dp[cur][x1][x2] = (dp[cur][x1][x2] + dp[cur ^ 1][x1][x2]) % MOD;
          dp[cur][x1][x2] = (dp[cur][x1][x2] + dp[cur ^ 1][x1][x2 + 1]) % MOD;
          dp[cur][x1][x2] = (dp[cur][x1][x2] + dp[cur ^ 1][x1 - 1][x2]) % MOD;
          dp[cur][x1][x2] =
              (dp[cur][x1][x2] + dp[cur ^ 1][x1 - 1][x2 + 1]) % MOD;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + dp[cur][i][i]) % MOD;
  }
  if ((m + n) % 2) {
    for (int i = 1; i <= n - 1; i++) {
      ans = (ans + dp[cur][i][i + 1]) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
