#include #define fi first #define se second #define rep(i,s,n) for (int i = (s); i < (n); ++i) #define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define len(x) (int)(x).size() #define dup(x,y) (((x)+(y)-1)/(y)) #define pb push_back #define eb emplace_back #define Field(T) vector> #define pq(T) priority_queue, greater> using namespace std; using ll = long long; using ull = unsigned long long; using P = pair; templatebool chmax(T&a,T b){if(abool chmin(T&a,T b){if(b struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { assert(x); int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using mint = ModInt<998244353>; int main() { int h, w; cin >> h >> w; vector s(h); rep(i,0,h) cin >> s[i]; vector> dp(w, vector(w)), ndp(w, vector(w)); dp[0][1] = 1; rep(t,0,h+w-4) { rep(i,0,w) fill(all(ndp[i]), 0); rep(i,0,w-1) rep(j,i+1,w) { int x = t+1-i, y = i, p = t+1-j, q = j; if (x < 0 || x >= h || p < 0 || p >= h) continue; rep(d,0,4) { int nx = x+(d%2 == 0), ny = y+(d%2 == 1); int np = p+(d/2 == 0), nq = q+(d/2 == 1); if (nx < 0 || nx >= h || ny < 0 || ny >= w || np < 0 || np >= h || nq < 0 || nq >= w) continue; if (ny == nq || s[nx][ny] == '#' || s[np][nq] == '#') continue; ndp[ny][nq] += dp[y][q]; } } // rep(i,0,w) { // rep(j,0,w) { // cout << ndp[i][j] << " "; // } // cout << endl; // } // cout << endl; swap(dp, ndp); } cout << dp[w-2][w-1] << endl; return 0; }