#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int maxn = 600;
int n, m, mid;
char a[maxn][maxn];
long long f1[maxn][maxn], f2[maxn][maxn], res;
void OpenFile() {
  freopen(
      "Pig and Palindromes"
      ".INP",
      "r", stdin);
  freopen(
      "Pig and Palindromes"
      ".OUT",
      "w", stdout);
}
void Enter() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
}
void Init() {}
int Y(int first, int s) { return s - first; }
void Solve() {
  if (a[1][1] != a[n][m]) {
    cout << 0;
    return;
  }
  f2[1][n] = 1;
  for (int ul = 2, dr = n + m; ul <= dr; ++ul, --dr) {
    for (int x1 = 1; x1 <= n; ++x1)
      for (int x2 = 1; x2 <= n; ++x2) {
        int y1 = Y(x1, ul);
        int y2 = Y(x2, dr);
        if (y1 <= 0 || y2 <= 0 || x1 > x2 || y1 > y2 || a[x1][y1] != a[x2][y2])
          f1[x1][x2] = 0;
        else {
          f1[x1][x2] = (f2[x1][x2] + f2[x1 - 1][x2] + f2[x1][x2 + 1] +
                        f2[x1 - 1][x2 + 1]) %
                       Mod;
        }
      }
    mid = ul;
    swap(f1, f2);
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) res = (res + f2[i][j]) % Mod;
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Enter();
  Init();
  Solve();
}
