#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*

*/

char add_wbr(char a, char b){
  if (a==b) return(a);
  if (a=='W' && b=='R') return('B');
  if (a=='W' && b=='B') return('R');
  if (a=='B' && b=='W') return('R');
  if (a=='B' && b=='R') return('W');
  if (a=='R' && b=='W') return('B');
  if (a=='R' && b=='B') return('W');
  return (0);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  ll N;
  string S;
  cin >> N >> S;
  ll sz=S.size();
  while (sz>1){ // 4->1, 5->4->1
    while(sz%3!=1){
      string T;
      for(ll j=0; j<sz-1; j++)
        T+=add_wbr(S[j], S[j+1]);
      S=T;
      sz=S.size();
    }
    string T;
    for(ll j=0; j+3<sz; j+=3)
      T+=add_wbr(S[j], S[j+3]);
    if (T[0]) S=T;
    sz=S.size();
  }
  cout << S[0] << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v[n];
    int x, y, z;
    rep(i, m) {
        cin >> x >> y >> z;
        x--;
        v[x].emplace_back(y, z);
    };
    ll dp[1 << n] = {};
    dp[0] = 1;
    for (int bit = 0; bit < 1 << n; bit++) {
        if (!dp[bit]) continue;
        rep(use, n) {
            if (bit >> use & 1) continue;
            int nxt = bit | 1 << use;
            bool ng = false;
            for (auto p : v[__builtin_popcount(bit)]) {
                int cnt = 0;
                rep(k, p.first) {
                    cnt += (nxt >> k) & 1;
                }
                if (cnt > p.second) {
                    ng = true;
                    break;
                }
            }
            if (ng) continue;
            dp[nxt] += dp[bit];
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}