#include <algorithm> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <iostream> #include <queue> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; int ret; map<string,int> memo; void solve(int Kr, int Kb, string S){ if(ret > S.length()) return; if(memo.count(S) > 0) return; memo[S] = 1; bool flg = false; rep(i,S.length()){ if(S[i] == 'R' && i+Kr<S.length() && S[i+Kr]=='R') flg = true; if(S[i] == 'B' && i+Kb<S.length() && S[i+Kb]=='B') flg = true; } if(flg){ rep(i,S.length()){ solve(Kr, Kb, S.substr(0,i) + S.substr(i+1)); } }else{ ret = max(ret, (int)(S.length())); } } int main(){ int Kr, Kb; string S; cin >> Kr >> Kb; cin >> S; ret = 3; solve(Kr, Kb, S); cout << ret << endl; return 0; }