#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int mod = MOD;
struct ModInt {
  unsigned val;
  ModInt(): val(0) {}
  ModInt(ll x) : val(x >= 0 ? x % mod : x % mod + mod) {}
  ModInt pow(ll exponent) {
    ModInt tmp = *this, res = 1;
    while (exponent > 0) {
      if (exponent & 1) res *= tmp;
      tmp *= tmp;
      exponent >>= 1;
    }
    return res;
  }
  ModInt &operator+=(const ModInt &x) { if((val += x.val) >= mod) val -= mod; return *this; }
  ModInt &operator-=(const ModInt &x) { if((val += mod - x.val) >= mod) val -= mod; return *this; }
  ModInt &operator*=(const ModInt &x) { val = static_cast<unsigned long long>(val) * x.val % mod; return *this; }
  ModInt &operator/=(const ModInt &x) { return *this *= x.inv(); }
  bool operator==(const ModInt &x) const { return val == x.val; }
  bool operator!=(const ModInt &x) const { return val != x.val; }
  bool operator<(const ModInt &x) const { return val < x.val; }
  bool operator<=(const ModInt &x) const { return val <= x.val; }
  bool operator>(const ModInt &x) const { return val > x.val; }
  bool operator>=(const ModInt &x) const { return val >= x.val; }
  ModInt &operator++() { if (++val == mod) val = 0; return *this; }
  ModInt operator++(int) { ModInt res = *this; ++*this; return res; }
  ModInt &operator--() { val = (val == 0 ? mod : val) - 1; return *this; }
  ModInt operator--(int) { ModInt res = *this; --*this; return res; }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { return ModInt(val ? mod - val : 0); }
  ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
  ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
  ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
  ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; }
  friend ostream &operator<<(ostream &os, const ModInt &x) { return os << x.val; }
  friend istream &operator>>(istream &is, ModInt &x) { ll val; is >> val; x = ModInt(val); return is; }
private:
  ModInt inv() const {
    // assert(__gcd(val, mod) == 1);
    unsigned a = val, b = mod; int x = 1, y = 0;
    while (b) {
      unsigned tmp = a / b;
      swap(a -= tmp * b, b);
      swap(x -= tmp * y, y);
    }
    return ModInt(x);
  }
};
ModInt abs(const ModInt &x) { return x; }
struct Combinatorics {
  int val; // "val!" and "mod" must be disjoint.
  vector<ModInt> fact, fact_inv, inv;
  Combinatorics(int val = 10000000) : val(val), fact(val + 1), fact_inv(val + 1), inv(val + 1) {
    fact[0] = 1;
    FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i;
    fact_inv[val] = ModInt(1) / fact[val];
    for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i;
    FOR(i, 1, val + 1) inv[i] = fact[i - 1] * fact_inv[i];
  }
  ModInt nCk(int n, int k) {
    if (n < 0 || n < k || k < 0) return ModInt(0);
    // assert(n <= val && k <= val);
    return fact[n] * fact_inv[k] * fact_inv[n - k];
  }
  ModInt nPk(int n, int k) {
    if (n < 0 || n < k || k < 0) return ModInt(0);
    // assert(n <= val);
    return fact[n] * fact_inv[n - k];
  }
  ModInt nHk(int n, int k) {
    if (n < 0 || k < 0) return ModInt(0);
    return (k == 0 ? ModInt(1) : nCk(n + k - 1, k));
  }
};

int main() {
  int h, w; cin >> h >> w;
  vector<string> a(h); REP(i, h) cin >> a[i];
  Combinatorics com(max(h, w));

  // dp[i][j]: i x j のマス目においてすべての行と列に対して操作を行う場合に
  //           得られるマス目の塗られ方の個数
  // dp_sub[i][j][k] における k は直前に k = 0 ... まだ何も見ていないか を意味する
  //                                         1     行を見たか
  //                                         2     列
  vector<vector<vector<ModInt> > > dp_sub(h + 1, vector<vector<ModInt> >(w + 1, vector<ModInt>(3, 0)));
  dp_sub[0][0][0] = 1;
  REP(i, h + 1) REP(j, w + 1) {
    FOR(k, i + 1, h + 1) dp_sub[k][j][1] += (dp_sub[i][j][0] + dp_sub[i][j][2]) * com.fact_inv[k - i];
    FOR(k, j + 1, w + 1) dp_sub[i][k][2] += (dp_sub[i][j][0] + dp_sub[i][j][1]) * com.fact_inv[k - j];
  }
  vector<vector<ModInt> > dp(h + 1, vector<ModInt>(w + 1));
  REP(i, h + 1) REP(j, w + 1) dp[i][j] = accumulate(ALL(dp_sub[i][j]), ModInt(0)) * com.fact[i] * com.fact[j];

  // pat[i][j]: i 行 j 列に対して操作を行う場合に得られるマス目の塗られ方の個数
  //            ただし行・列いずれに関しても操作が行われないマスは無視する
  vector<vector<ModInt> > pat(h + 1, vector<ModInt>(w + 1, 0));
  REP(i, h + 1) REP(j, w + 1) {
    // y 行 x 列白く塗る
    REP(y, i + 1) REP(x, j + 1) pat[i][j] += com.nCk(i, y) * com.nCk(j, x) * dp[y][j - x] * dp[i - y][x];
  }

  ModInt ans = 0;
  REP(i, 1 << h) REP(j, 1 << w) { // 行 i, 列 j を残す
    if (__builtin_popcount(i) < 2 || __builtin_popcount(j) < 2) continue;
    vector<vector<char> > left; // 残ったマス目
    REP(y, h) if (i >> y & 1) {
      left.emplace_back();
      REP(x, w) if (j >> x & 1) left.back().emplace_back(a[y][x]);
    }
    bool ok = true;
    // 行を見る
    REP(y, left.size()) {
      bool same = true;
      FOR(x, 1, left[y].size()) same &= left[y][x - 1] == left[y][x];
      ok &= !same;
    }
    // 列を見る
    REP(x, left.front().size()) {
      bool same = true;
      FOR(y, 1, left.size()) same &= left[y - 1][x] == left[y][x];
      ok &= !same;
    }
    if (ok) ans += pat[h - __builtin_popcount(i)][w - __builtin_popcount(j)];
  }
  // 何も残さない
  ans += dp[h][w];

  cout << ans << '\n';
  return 0;
}
