/**
*!! God will direct your steps !!
* @Author  : Ekansh Saxena (ekansh9927)
* @DateTime: 19-12-2020  17:59:21
*
**/
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define pll pair<long long,long long>
#define B begin()
#define E end()
#define usi unordered_set<int>
#define usll unordered_set<long long>
#define uslli unordered_set<long long int>
#define umll unordered_map<long long,long long>
#define umlli unordered_map<long long int,long long int>
#define umstoll unordered_map<string,long long>
#define umchtoll unordered_map<char,long long>
#define vi vector<int>
#define vll vector<long long>
#define vlli vector<long long int>
#define vpll vector<pair<long long,long long>>
#define sortall(arr) sort(arr.begin(),arr.end())
#define modadd(a,b) (a%mod + b%mod)%mod
#define modsub(a,b) (a%mod - b%mod)%mod
#define modmul(a,b) (a%mod * b%mod)%mod
#define REP(n) for(int i=0;i<n;i++)
#define FOR(i,l,r,in) for(i=l;i<r;i+=in)
#define FILL(n,arr) for(int i=0;i<n;i++){ll x;cin>>x;arr.pb(x);}
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef long long int lli;
//___________________________________POWER____________________________________________
ll power(ll x, ll y, ll p){
ll res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0)
{ 
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
//_______________________________END-OF-POWER__________________________________________



void solve(){
ll n,m;
cin>>n>>m;
cout<<n/m<<endl;

}

int main(){
    FIO;
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
#include <math.h>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <vector>
#include <cmath>
#include<set>
#include <sstream>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()//配列を全部参照

using namespace std;
using ll = long long int;
using Graph = vector<vector<int>>; // グラフ型
//cin.tie(nullptr); /*高速で入力可能*/
//vector<vector<int>> hako(n, vector<int>(2));
//sort(hako.begin(), hako.end(), [](const vector<int>& alpha, const vector<int>& beta) {return alpha[0] < beta[0]; });


int main() {
	cin.tie(nullptr);
	ll n,h,w;
	ll ans = 1;
	cin >> h >> w;
	vector<vector<char>> hako(h, vector<char>(w));
	vector<bool> R(h + w-1), B(h + w-1);
	rep(i, h)rep(j, w) cin >> hako[i][j];
	rep(i, h)rep(j, w) {
		if (hako[i][j] == 'R') R[i + j] = true;
		if (hako[i][j] == 'B') B[i + j] = true;
	}
	
	rep(i, h + w-1) {
		if (R[i] && B[i]) ans = 0;
		if (!R[i] && !B[i]) ans = ans * 2 % 998244353;
	}

	cout << ans << endl;
	return 0;
}
