#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef long long ll;

//infの設定
#define INF32 2147483647
#define INF64 9223372036854775807
//repマクロ
#define rep(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))


int main(){
    ll H,W;
    vector<string> S(1010),x(1010);

    cin>>H>>W;
    rep(i,0,H) cin>>S.at(i);

    ll line=H+W-1;
    int hantei=0;

    rep(i,0,H+W-1){
        hantei=0;
        rep(j,0,W){
            if(0<=i-j&&i-j<H){
                if(S.at(i-j).at(j)=='R'){
                    if(hantei==2){
                        cout<<"0"<<endl;
                        return 0;
                    }else{
                        hantei=1;
                    }
                }else if(S.at(i-j).at(j)=='B'){
                    if(hantei==1){
                        cout<<"0"<<endl;
                        return 0;
                    }else{
                        hantei=2;
                    }
                }
            }
        }
        if(hantei!=0) line--;
    }
    ll ans=1;
    rep(i,0,line) ans=(ans*2)%998244353;

    cout<<ans<<endl;
    return 0;
}
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define int ll

int dp[105][105][105];
int n, k, x;
int a[105];
int calc(int ind, int taken, int sum){
    if(ind == n){
        if(taken == k && sum == x%k){
            return 0;
        }
        else{
            return -1e18;
        }
    }
    if(taken == k){
        if(sum == x%k){
            return 0;
        }
        else{
            return -1e18;
        }
    }
    if(dp[ind][taken][sum] != -1){
        return dp[ind][taken][sum];
    }
    int ch1 = calc(ind + 1, taken + 1, (sum + a[ind])%k) + a[ind];
    int ch2 = calc(ind + 1, taken, sum);
    return dp[ind][taken][sum] = max(ch1, ch2);
}
int32_t main(){
    FAST
    cin >> n >> x;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 1e18;
    for(int i = 1; i <= n; i++){
        memset(dp, -1, sizeof(dp));
        k = i;
        int x2 = x - calc(0, 0, 0);
        if(x2 > x)continue;
        if(x2%i == 0){
            ans = min(ans, x2/i);
        }
    }
    cout << ans;
    return 0;
}
