#include<bits/stdc++.h>
using namespace std;

#define int int64_t

const int MOD = 998244353;
const int N = 5005;

int P[N][N];

int power(int x, int y) {
    if (P[x][y] != -1) return P[x][y];
    if (y < 0) return 0;
    int u = x;
    int v = y;
    int res = 1;
    while (y) {
        if (y % 2) res = res * x % MOD;
        y >>= 1;
        x = x * x % MOD;
    }
    return P[u][v] = res;
}


int32_t main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) P[i][j] = -1;
    }
    int64_t res = 0;
    for (int h = 1; h <= m; h++) {
        for (int l = 1; l <= n; l++) {
            if (l == n) {
                res += (power(m - h + 1, l) - power(m - h, l) + MOD) % MOD;
                res %= MOD;
            } else {
                res += (n - l - 1) * (power(m - h + 1, l) - power(m - h, l) + MOD) % MOD * power(h - 1, 2) % MOD * power(m, n - l - 2) % MOD;
                res %= MOD;
                res += 2 * (power(m - h + 1, l) - power(m - h, l) + MOD) % MOD * (h - 1) % MOD * power(m, n - l - 1) % MOD;
                res %= MOD;
            }
        }
    }
    cout << res << '\n';
    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

char s[2000][2001];
int a[2000][2000];
int b[2000][2000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int h, w;
    cin >> h >> w;

    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    for (int i = 0; i < h; i++) {
        int k = 0;
        for (int j = 0; j <= w; j++) {
            if (j == w || s[i][j] == '#') {
                for (int l = j - k; l < j; l++) {
                    a[i][l] = k;
                }
                k = 0;
            } else {
                k++;
            }
        }
    }
    for (int j = 0; j < w; j++) {
        int k = 0;
        for (int i = 0; i <= h; i++) {
            if (i == h || s[i][j] == '#') {
                for (int l = i - k; l < i; l++) {
                    b[l][j] = k;
                }
                k = 0;
            } else {
                k++;
            }
        }
    }

    vector<int> x(h * w + 1);
    x[0] = 1;
    for (int i = 1; i <= h * w; i++) {
        x[i] = x[i - 1] * 2 % P;
    }

    ll r = 0;
    int l = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') continue;

            l++;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') continue;

            int k = a[i][j] + b[i][j] - 1;
            r += (ll)x[l - k] * (x[k] - 1) % P;
        }
    }

    r %= P;
    if (r < 0) r += P;

    cout << r << endl;

    //マスの立場で考えると、この範囲に明かりが一つでもあるか

    return 0;
}