#include<bits/stdc++.h>
using namespace std;
const int N=1005,mod=998244353;
int n,m,f1[N],f2[N],t;
char s[N][N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='R')
				f1[i+j]=1;
			if(s[i][j]=='B')
				f2[i+j]=1;
		}
	}
	t=1;
	for(int i=2;i<=n+m;i++)
	{
		if(f1[i]&&f2[i])
		{
			puts("0");
			return 0;
		}
		if(!f1[i]&&!f2[i])
			t=t*2%mod;
	}
	printf("%d\n",t);
	return 0;
}
// F - Potion
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll INF = 1e18;
ll dp[101][101];

void init(int k){
	rep(i,k+1) rep(j,k) dp[i][j] = -INF;
	dp[0][0] = 0;
}

void update(int k, int a){
	for(int i=k-1; i>=0; --i) rep(j,k){
		int sk = (j + a) % k;
		dp[i+1][sk] = max(dp[i+1][sk], dp[i][j] + a);
	}
}

int main(){
	int n; ll x; cin>>n>>x;
	int A[n]; for(auto&a:A) cin>>a;
	ll ans = INF;
	for(int k=1; k<=n; ++k){
		init(k);
		for(int a:A) update(k, a);
		ll s = dp[k][x%k];
		if(s >= 0) ans = min(ans, (x-s)/k);
	}
	cout<< ans <<endl;
}
