#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template <class T>
void CVEC(const T &v) {
	int c = v.size() - 1;
	for (int i = 0; i < c; i++) cout << v[i] << ' ';
	if (c > -1) cout << v[c];
	cout << '\n';
}


signed main(){
    int n, T;
	cin >> n >> T;
	vi a(n);
	rep(i,n) cin >> a[i];
	vi s,t;
	s = t = {0};
	rep(i,n){
		for(int j = s.size() - 1; j >= 0; --j){
			s.push_back(s[j] + a[i]);
		}
		swap(s, t);
	}
	sort(ALL(s));
	int ans = 0;
	each(x, t){
		if(x > T) continue;
		int si = upper_bound(ALL(s), T - x) - s.begin();
		ans = max(ans, x + s[si - 1]);//sには0が入っているのでsi-1<0にはならない
	}
	cout << ans << endl;
	return 0;
}
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


const int mod = 998244353;
int main() {
	int R, C;
	cin >> R >> C;
	vector<string> grid(R);
	for (int i = 0; i < R; i++) {
		cin >> grid[i];
	}

	ll ans = 1;
	vector<bool> hasRed(R + C - 1), hasBlue(R + C - 1);
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			if (grid[i][j] == 'R') {
				hasRed[i + j] = true;
			}
			if (grid[i][j] == 'B') {
				hasBlue[i + j] = true;
			}
		}
	}

	for (int i = 0; i < R + C - 1; i++) {
		if (hasRed[i] && hasBlue[i]) {
			ans = 0;
		}
		if (!hasRed[i] && !hasBlue[i]) {
			ans = (ans << 1) % mod;
		}
	}
	cout << ans << endl;
}