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

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int) x.size()
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define FOR(i, a, b) for(auto i=(a); i<(b); i++)
#define ROF(i, a, b) for(auto i=(b)-1; i>=(a); i--)
#define F0R(i, n) FOR(i, 0, n)
#define R0F(i, n) ROF(i, 0, n)

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vpii=vector<pii>;

template<class T> bool ckmin(T&a, const T&b) {return b<a?a=b,1:0;}
template<class T> bool ckmax(T&a, const T&b) {return b>a?a=b,1:0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=1001;
const int MOD=998244353; 
const ll infLL=1e18;
const ld eps=1e-6;

template<int mod> struct mint {
	int v; explicit operator int() const{return v;} 
	mint() {v=0;}
	mint(ll _v) { v =int((-mod< _v&&_v<mod)?_v:_v%mod);
		if(v < 0) v+=mod;}
	friend bool operator==(const mint& a, const mint& b){ 
		return a.v==b.v;}
	friend bool operator!=(const mint& a, const mint& b){ 
		return !(a==b);}
	friend bool operator<(const mint& a, const mint& b){ 
		return a.v<b.v;}
	mint& operator+=(const mint& m) { 
		if((v+=m.v)>=mod) v-=mod; 
		return *this;}
	mint& operator-=(const mint& m) { 
		if((v-=m.v)<0) v+=mod; 
		return *this;}
	mint& operator*=(const mint& m){ 
		v=int((ll)v*m.v%mod); return *this;}
	mint& operator/=(const mint& m) {return (*this)*=inv(m);}
	friend mint pow(mint a, ll p) {
		mint ans = 1; assert(p >= 0);
		for (;p;p/=2,a*=a) if(p&1) ans*=a;
		return ans;}
	friend mint inv(const mint& a){assert(a.v!=0); 
		return pow(a,mod-2);}
	mint operator-() const{return mint(-v);}
	friend mint operator+(mint a, const mint& b) {return a+=b;}
	friend mint operator-(mint a, const mint& b) {return a-=b;}
	friend mint operator*(mint a, const mint& b) {return a*=b;}
	friend mint operator/(mint a, const mint& b) {return a/=b;}
};

using mi=mint<MOD>;

vector<mi> invs, fac, ifac; 
void genFac(int SZ=mxN) {
	invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ); vi Invs(SZ);
	Invs[1]=1; invs[1]=fac[0]=ifac[0]=1; 
	FOR(i,2,SZ) Invs[i] = int(MOD-(ll)MOD/i*Invs[MOD%i]%MOD), invs[i]=mi(Invs[i]);
	FOR(i,1,SZ) {
		fac[i]=fac[i-1]*i;
		ifac[i]=ifac[i-1]*invs[i];
	}
}

mi choose(int n, int k){
	if(k>n) return 0;
	return fac[n]*ifac[n-k]*ifac[k];
}

int n, m;
string a[mxN];
vpii dist[mxN]; 
mi ans=1;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	F0R(i, n) cin >> a[i]; 
	F0R(i, n){
		F0R(j, m){
			dist[i+j].pb({i, j});
		}
	}
	F0R(i, n+m-1){
		int cntA=0, cntB=0, M=siz(dist[i]);
		for(auto [x, y]:dist[i]){
			cntA+=a[x][y]=='B'; 
			cntB+=a[x][y]=='R'; 
		}
		if(cntA>0&&cntB>0){
			cout << "0\n"; return 0; 
		}
		if(cntA==0&&cntB==0){
			ans*=2;
		}
	}
	cout << ans.v << "\n";
	return 0; 
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
using namespace std;

unsigned long long g2(unsigned long long N) {
	int* ar = new int[(int)log10(N)+1];
	unsigned long long a = 0;
	
	for (int i = 0; i <= (int)log10(N); i++) {
		ar[i] = (int)(N / pow(10, i)) % 10;
	}

	sort(ar, ar + (int)log10(N) + 1, greater<>());

	for (int i = 0; i < (int)log10(N) + 1; i++) {
		a += ar[i] * pow(10, i);
	}

	return a;
}
unsigned long long g1(unsigned long long N) {
	int* ar = new int[(int)log10(N) + 1];
	unsigned long long a = 0;
	for (int i = 0; i <= (int)log10(N); i++) {
		ar[i] = (int)(N / pow(10, i)) % 10;
	}

	sort(ar, ar + (int)log10(N) + 1);
	for (int i = 0; i < (int)log10(N) + 1; i++) {
		a += ar[i] * pow(10, i);
	}
	return a;
}
int main() {
	unsigned long long N, K,a;

	cin >> N >> K;
	a = N;
	for (int i = 0; i < K; i++) {
		//cout << g1(a) << " " << g2(a) << endl;
		if (!a) break;
		a = g1(a) - g2(a);
	
	}

	cout << a;
	return 0;
}
