#include using namespace std; using ll = long long; using vi = vector; using vb = vector; using vd = vector; using vl = vector; using vvi = vector; using vvb = vector; using vvd = vector; using vvl = vector; #define REP(i,n) for(ll i=0; i<(n); ++i) ll kr, kb; string s; vl pos; ll recur(ll depth, vb & enable){ if (depth == pos.size()) { string ns; REP(i, s.size()) if (enable[i]) ns.push_back(s[i]); REP(i, ns.size()) { if (ns[i] == 'W') continue; ll d = ns[i] == 'R' ? kr : kb; if (i - d >= 0 && ns[i - d] == ns[i]) return -1; if (i + d < ns.size() && ns[i + d] == ns[i]) return -1; } return ns.size(); } ll ans = recur(depth + 1, enable); enable[pos[depth]] = false; ans = max(ans, recur(depth + 1, enable)); enable[pos[depth]] = true; return ans; } int main() { cin >> kr >> kb >> s; REP(i, s.size()) if(s[i]!='W') pos.push_back(i); vb enable(s.size(), true); cout << recur(0, enable) << endl; return 0; }