#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int maxn = 510;
long long dp[2][maxn][maxn];
const long long mod = 1000000007;
char ma[maxn][maxn];
char m2[maxn][maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ma[i] + 1);
    for (int j = 1; j <= m; j++) {
      m2[j][i] = ma[i][j];
    }
  }
  if (n > m) {
    swap(n, m);
    for (int i = 1; i <= n; i++) memcpy(ma[i] + 1, m2[i] + 1, m);
  }
  int len = (n + m) / 2;
  for (int x1 = 1; x1 <= len; x1++) {
    int y1 = len + 1 - x1;
    for (int xx = 1; xx <= len; xx++) {
      int yy = len + 1 - xx;
      int x2 = n + 1 - xx;
      int y2 = m + 1 - yy;
      if (x1 <= x2 && y1 <= y2 && abs(x1 - x2) + abs(y1 - y2) <= 1 &&
          ma[x1][y1] == ma[x2][y2]) {
        dp[0][x1][x2] = 1;
      }
    }
  }
  bool cur = 0;
  bool las = 1;
  for (int z = len - 1; z >= 1; --z) {
    swap(cur, las);
    memset(dp[cur], 0, sizeof(dp[cur]));
    for (int i = 1; i <= min(n, z); i++) {
      int x1 = i;
      int y1 = z + 1 - x1;
      for (int j = 1; j <= min(n, z); j++) {
        int jj = z + 1 - j;
        int x2 = n + 1 - j;
        int y2 = m + 1 - jj;
        if (x1 <= x2 && y1 <= y2 && ma[x1][y1] == ma[x2][y2]) {
          if (y1 + 1 <= m && y2 - 1 >= 1 && ma[x1][y1 + 1] == ma[x2][y2 - 1])
            dp[cur][x1][x2] += dp[las][x1][x2];
          if (y1 + 1 <= m && x2 - 1 >= 1 && ma[x1][y1 + 1] == ma[x2 - 1][y2])
            dp[cur][x1][x2] += dp[las][x1][x2 - 1];
          if (x1 + 1 <= n && y2 - 1 >= 1 && ma[x1 + 1][y1] == ma[x2][y2 - 1])
            dp[cur][x1][x2] += dp[las][x1 + 1][x2];
          if (x1 + 1 <= n && x2 - 1 >= 1 && ma[x1 + 1][y1] == ma[x2 - 1][y2])
            dp[cur][x1][x2] += dp[las][x1 + 1][x2 - 1];
          dp[cur][x1][x2] %= mod;
        }
      }
    }
  }
  printf("%lld\n", dp[cur][1][n]);
  return 0;
}
