#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 10;
const i64 P = 998244353;
string s[maxn];

i64 mult[maxn + 1][maxn + 1];
i64 dp[maxn + 1][maxn + 1][16];
i64 cnk[maxn + 1][maxn + 1];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    cnk[0][0] = 1;
    forn(i, maxn) forn(j, i + 1) forn(z, 2) cnk[i + 1][j + z] += cnk[i][j];

    int n, m;
    cin >> n >> m;
    forn(i, n) cin >> s[i];

    forn(h, n + 1) forn(w, m + 1) {
        if (min(w, h) == 0 && max(w, h) != 0) continue;
        forn(i, n + 1) forn(j, m + 1) forn(mask, 16) dp[i][j][mask] = 0;
        dp[n][m][0] = 1;
        i64 res = 0;
        ford(i, n + 1) ford(j, m + 1) forn(mask, 16) {
            if (i < h) continue;
            if (j < w) continue;
            if (dp[i][j][mask] == 0) continue;
//            if (h == 0) cerr << i << ' ' << j << ' ' << mask << ' ' << dp[i][j][mask] << '\n';
            if (min(i, j) == 0) {
                res += dp[i][j][mask];
                res %= P;
                continue;
            }
            forn(br, i - h + 1) forn(wr, i - h - br + 1) forn(bc, j - w + 1) forn(wc, j - w - bc + 1) {
                if ((mask & 1) && br > 0) continue;
                if ((mask & 2) && wr > 0) continue;
                if ((mask & 4) && bc > 0) continue;
                if ((mask & 8) && wc > 0) continue;
                if (br > 0 && wc > 0) continue;
                if (wr > 0 && bc > 0) continue;
                if (br + wr + bc + wc == 0) continue;
                if (wr == i && wc < j) continue;
                if (br == i && bc < j) continue;
                if (wc == j && wr < i) continue;
                if (bc == j && br < i) continue;

                i64 coef = cnk[i - h][br + wr] * cnk[br + wr][br] % P * cnk[j - w][bc + wc] % P * cnk[bc + wc][bc] % P;
                int nmask = 0;
                if (bc + wc == 0) nmask |= 3;
                if (br + wr == 0) nmask |= 12;
                if (br + bc == 0) nmask |= 10;
                if (wr + wc == 0) nmask |= 5;
                i64 &newVal = dp[i - wr - br][j - wc - bc][nmask];
                newVal += dp[i][j][mask] * coef;
                newVal %= P;
            }
        }
        mult[h][w] = res;
        if (h > 0) forn(mask, 16) mult[h][w] += dp[h][w][mask];
        mult[h][w] %= P;
    }

    i64 ans = 0;
    forn(rmask, 1 << n) forn(cmask, 1 << m) {
        if (min(rmask, cmask) == 0 && max(rmask, cmask) > 0) continue;
        bool ok = true;
        if (rmask != 0) {
            forn(i, n) {
                if (!((rmask >> i) & 1)) continue;
                bool hasB = false, hasW = false;
                forn(j, m) {
                    if (!((cmask >> j) & 1)) continue;
                    if (s[i][j] == '#') hasB = true;
                    else hasW = true;
                }
                if (!hasB || !hasW) ok = false;
            }

            forn(j, m) {
                if (!((cmask >> j) & 1)) continue;
                bool hasB = false, hasW = false;
                forn(i, n) {
                    if (!((rmask >> i) & 1)) continue;
                    if (s[i][j] == '#') hasB = true;
                    else hasW = true;
                }
                if (!hasB || !hasW) ok = false;
            }
        }
        if (!ok) continue;
        ans += mult[__builtin_popcount(rmask)][__builtin_popcount(cmask)];
        ans %= P;
    }    
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
	

Measured memory_bytes: 256