#include <bits/stdc++.h>
using namespace std;
long long POW(long long A, long long N, long long MOD) {
  if (N == 0) return 1 % MOD;
  if (N == 1) return A % MOD;
  long long tmp = POW(A, N / 2, MOD) % MOD;
  if (N % 2)
    return ((tmp * tmp) % MOD * A % MOD) % MOD;
  else
    return (tmp * tmp) % MOD;
}
long long MUL(long long A, long long B, long long MOD) {
  long long r = 0;
  while (B) {
    r = (r + (A * (B % 2) % MOD)) % MOD;
    A = (A + A) % MOD;
    B /= 2;
  }
  return r;
}
long long GCD(long long A, long long B) { return B == 0 ? A : GCD(B, A % B); }
int dx[] = {0, -1, 0, 1, 0};
int dy[] = {-1, 0, 1, 0, -1};
template <class X, class Y>
bool minimize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x > y + eps) {
    x = y;
    return true;
  } else
    return false;
}
template <class X, class Y>
bool maximize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x + eps < y) {
    x = y;
    return true;
  } else
    return false;
}
template <class T>
T Abs(const T &x) {
  return (x < 0 ? -x : x);
}
const int MAXN = 505;
const long long MOD = 1e9 + 7;
int N, M;
char A[MAXN][MAXN];
vector<vector<vector<vector<int> > > > dp;
bool Inside(int x, int y) {
  if (x < 1 || y < 1 || x > N || y > M) return 0;
  return 1;
}
namespace SubtaskTRAU {
int solve(int x, int y, int u, int v) {
  if (x == u && y == v) return 1;
  if (x > u || y > v) return 0;
  if (x == u && abs(y - v) == 1) return 1;
  if (y == v && abs(x - u) == 1) return 1;
  if (dp[x][y][u][v] != -1) return dp[x][y][u][v];
  long long cur = 0;
  for (int h1 = (2), _b = (3); h1 <= _b; ++h1) {
    int nx = x + dx[h1];
    int ny = y + dy[h1];
    if (!Inside(nx, ny)) continue;
    for (int h2 = (0), _b = (1); h2 <= _b; ++h2) {
      int nu = u + dx[h2];
      int nv = v + dy[h2];
      if (!Inside(nu, nv)) continue;
      if (A[nx][ny] != A[nu][nv]) continue;
      cur += solve(nx, ny, nu, nv);
      cur %= MOD;
    }
  }
  return dp[x][y][u][v] = cur;
}
void SOLVE() {
  dp.assign(N + 5,
            vector<vector<vector<int> > >(
                M + 5, vector<vector<int> >(N + 5, vector<int>(M + 5, -1))));
  if (A[1][1] != A[N][M])
    cout << 0 << '\n';
  else
    cout << solve(1, 1, N, M) << '\n';
}
}  // namespace SubtaskTRAU
namespace SubtaskFULL {
int CALC1(int x, int step) { return step - x + 2; }
int CALC2(int x, int step) { return N - x + M - step; }
int dp[MAXN][MAXN][252];
int solve(int x, int u, int step) {
  int y = CALC1(x, step);
  int v = CALC2(u, step);
  if (x == u && y == v) return 1;
  if (x > u || y > v) return 0;
  if (x == u && abs(y - v) == 1) return 1;
  if (y == v && abs(x - u) == 1) return 1;
  if (dp[x][u][step] != -1) return dp[x][u][step];
  long long cur = 0;
  for (int h1 = (2), _b = (3); h1 <= _b; ++h1) {
    int nx = x + dx[h1];
    int ny = y + dy[h1];
    if (!Inside(nx, ny)) continue;
    for (int h2 = (0), _b = (1); h2 <= _b; ++h2) {
      int nu = u + dx[h2];
      int nv = v + dy[h2];
      if (!Inside(nu, nv)) continue;
      if (A[nx][ny] != A[nu][nv]) continue;
      cur += solve(nx, nu, step + 1);
      cur %= MOD;
    }
  }
  return dp[x][u][step] = cur;
}
void SOLVE() {
  memset(dp, -1, sizeof(dp));
  if (A[1][1] != A[N][M])
    cout << 0 << '\n';
  else
    cout << solve(1, N, 0) << '\n';
}
}  // namespace SubtaskFULL
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> N >> M;
  for (int i = (1), _b = (N); i <= _b; ++i) {
    for (int j = (1), _b = (M); j <= _b; ++j) {
      cin >> A[i][j];
    }
  }
  SubtaskFULL ::SOLVE();
  return 0;
}
