MOD = 998244353i64 DY = [1, 0, -1, 0] DX = [0, 1, 0, -1] def pow(v : Int64, p) ret = 1i64 while p > 0 if (p & 1i64) != 0 ret *= v ret %= MOD end v *= v v %= MOD p >>= 1 end ret end n, m = read_line.split.map(&.to_i) s = Array.new(n) { read_line.chars } visited = Array.new(n) { Array.new(m, false) } ans = 1i64 n.times do |i| m.times do |j| next if s[i][j] == '.' || visited[i][j] q = [{i, j}] visited[i][j] = true qi = 0 ec = 0 while qi < q.size cy, cx = q[qi] qi += 1 4.times do |dir| ny = cy + DY[dir] nx = cx + DX[dir] if 0 <= ny < n && 0 <= nx < m && s[ny][nx] == '#' ec += 1 if !visited[ny][nx] visited[ny][nx] = true q << {ny, nx} end end end end ec //= 2 rm = {0, ec - q.size + 1}.max ans *= pow(2i64, q.size * 2 - rm) ans %= MOD end end puts ans