from collections import defaultdict H, W = map(int, input().split()) S = [list(input()) for _ in range(H)] MOD = 998244353 def IDX(h1, w1, h2, w2): return w1+h1*W+w2*H*W+h2*W*H*W def IDXR(n): return n%W, n//W%H, n//(H*W)%W, n//(W*H*W) dp = defaultdict(int) dp[IDX(1, 0, 0, 1)] = 1 for i in range(H+W-3): ndp = defaultdict(int) for key in dp.keys(): w1, h1, w2, h2 = IDXR(key) if w1+1 < W and w2+1 < W and S[h1][w1+1] == "." and S[h2][w2+1] == ".": ndp[IDX(h1, w1+1, h2, w2+1)] += dp[key] ndp[IDX(h1, w1+1, h2, w2+1)] %= MOD if h1+1 < H and h2+1 < H and S[h1+1][w1] == "." and S[h2+1][w2] == ".": ndp[IDX(h1+1, w1, h2+1, w2)] += dp[key] ndp[IDX(h1+1, w1, h2+1, w2)] %= MOD if w1+1 < W and h2+1 < H and S[h1][w1+1] == "." and S[h2+1][w2] == "." and ([h1, w1+1] == [H-1, W-1] or [h1, w1+1] != [h2+1, w2]): ndp[IDX(h1, w1+1, h2+1, w2)] += dp[key] ndp[IDX(h1, w1+1, h2+1, w2)] %= MOD if h1+1 < H and w2+1 < W and S[h1+1][w1] == "." and S[h2][w2+1] == "." and ([h1+1, w1] == [H-1, W-1] or [h1+1, w1] != [h2, w2+1]): ndp[IDX(h1+1, w1, h2, w2+1)] += dp[key] ndp[IDX(h1+1, w1, h2, w2+1)] %= MOD dp = ndp print(dp[IDX(H-1, W-1, H-1, W-1)])