#include typedef struct tree { struct tree *p; } tree; tree *get_root (tree *t) { if (t == NULL || t->p == NULL) { return t; } t->p = get_root(t->p); return t->p; } long long power_mod (long long a, long long b, long long mod_num) { long long ans = 1LL; if (b > 0LL) { ans = power_mod(a, b/2LL, mod_num); ans = (ans * ans) % mod_num; if (b%2LL == 1LL) { ans = (ans * a) % mod_num; } } return ans; } int main () { int n = 0; int m = 0; char s[500][501] = {}; int res = 0; int ans = 0; long long mod_num = 998244353LL; tree t[500][500] = {}; res = scanf("%d", &n); res = scanf("%d", &m); for (int i = 0; i < n; i++) { res = scanf("%s", s[i]); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s[i][j] == '#') { ans++; if (i <= 0 || s[i-1][j] != '#') { ans++; } if (j <= 0 || s[i][j-1] != '#') { ans++; } } t[i][j].p = NULL; } } for (int i = 0; i < n-1; i++) { for (int j = 0; j < m; j++) { if (s[i][j] == '#' && s[i+1][j] == '#') { tree *rt1 = get_root(t[i]+j); tree *rt2 = get_root(t[i+1]+j); if (rt1 != rt2) { rt2->p = rt1; } } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m-1; j++) { if (s[i][j] == '#' && s[i][j+1] == '#') { tree *rt1 = get_root(t[i]+j); tree *rt2 = get_root(t[i]+(j+1)); if (rt1 != rt2) { rt2->p = rt1; } } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s[i][j] == '#' && t[i][j].p == NULL) { ans--; } } } printf("%lld\n", power_mod(2LL, (long long)ans, mod_num)); return 0; }