#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    char s, t;
    cin >> s >> t;

    if(s == 'Y') {
        char c = toupper(t);
        out(c);
    }
    else {
        out(t);
    }
    
    re0;
}
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define rep(i,a,b) for(int i = (a) ; i<(b) ; ++i) 
#define ar array
#define ll long long
#define pb push_back
#define sz(v) (int)(v).size()
#define endl '\n'
#define dbg(x) cerr << #x << " = " << x << endl

const int N = int(2e5) + 99;
const int INF = int(1e9) + 99;
const int mxN = 1000005;
const int MOD = 998244353;
const int MASK = 4;

ll binpow(ll a, ll p, ll m) {
	a%=m;
	ll ans = 1;
	while(p>0) {
		if(p&1) ans *= a, ans%m;
		p>>=1;
		a*=a;
		a%=m;
	}
	return ans;
}
int h,w;
string s[1000];

bool valid(int x, int y) {
	return min(x,y) >=0 && x<h && y<w;
}

bool isvalidr(int x, int y) {
	int i=x,j=y;
	while(valid(i+1,j-1)) {
		++i,--j;
		if(s[i][j]=='B') return false;
	}
	i=x,j=y;
	while(valid(i-1,j+1)) {
		--i,++j;
		if(s[i][j]=='B') return false;
	}
	return true;
}

bool isvalid(int x, int y) {
	int i=x,j=y;
	while(valid(i+1,j-1)) {
		++i,--j;
		if(s[i][j]!='.') return false;
	}
	i=x,j=y;
	while(valid(i-1,j+1)) {
		--i,++j;
		if(s[i][j]!='.') return false;
	}
	return true;
}

bool vis[2000] = {false};

void solve() {
	cin>>h>>w;
	rep(i,0,h) cin>>s[i];
	ll ans = 1;
	set<char> st[h+w-1];
	rep(i,0,h) rep(j,0,w) {
		if(s[i][j]!='.') st[i+j].insert(s[i][j]);
	}
	rep(i,0,h+w-1) if(sz(st[i])==2) ans=0;else ans *= (st[i].empty())?2:1,ans%=MOD;
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--) {
		solve();
	}
}
