#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
ll M = 998244353;
vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    int n, m; cin >> n >> m;

    // if (m % 2 != 0) {
    //     cout << 0 << endl;
    //     return 0;
    // }

    vvec<ll> dp(14, vec<ll>(m+1, 0));
    vec<ll> pow2(15, 0);
    pow2[0] = 1;
    rep(i, 14) pow2[i+1] = pow2[i] * 2;

    // dp[0][0] = 1;
    rep(j, m + 1) if (j % 2 == 0) if (m >= j) if (n >= j) dp[0][j] = comb(n, j);

    for(int i = 1; i < 14; i++) for(int j = 0; j <= m; j++) {
        // if (i >= 2) break;
        int jn = 0;
        while(true) {
            if (j - jn * pow2[i + 1] < 0) break;
            if (n < jn * 2) break;
            // sum = j - jn;
            ll add = 0;
            add = dp[i-1][j - jn * pow2[i + 1]] * comb(n, jn*2);
            add %= M;
            // if ((i == 1) && (j == 20)) cout << jn << " " << add << endl;

            dp[i][j] += add;
            dp[i][j] %= M;
            // cout << i << " " << j << " " << jn << " " << add << endl;
            jn++;
        }
    }
    // rep(i, 14) {
    //     rep(j, m + 1) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    // cout << endl;

    cout << dp[13][m] << endl;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) {a = b; return 1;} return 0;}
template<class T> void print(const T &t) {cout << t << "\n";}
const ll INF = 1LL << 62;
const int iINF = 1 << 30;

int n;
ll a;
char c;
using vi = vector<int>;

ll check(vl&x, vl&y){
    if(x.empty() or y.empty()) return INF/2;
    ll res=INF;
    fore(z,x){
        auto tmp=lower_bound(all(y),z);
        ll t1=*tmp,t2=INF;
        if(tmp!=y.begin()) t2=*(--tmp);
        chmin(res,min(abs(z-t1),abs(z-t2)));
    }
    return res;
}

int main() {
    fio(); cin>>n;
    vl R,G,B;
    rep(i,2*n) {
        cin>>a>>c;
        if(c=='R') R.emplace_back(a);
        if(c=='G') G.emplace_back(a);
        if(c=='B') B.emplace_back(a);
    }
    sort(all(R));sort(all(G));sort(all(B));
    if(sz(R)%2==0 and sz(G)%2==0 and sz(B)%2==0) print(0);
    else{
        if(sz(G)%2==0) swap(R,G);
        else if(sz(B)%2==0) swap(R,B);
        print(min(check(G,B),check(B,R)+check(R,G)));
    }
}
