from collections import * from itertools import * from functools import * from heapq import * import sys,math # input = sys.stdin.readline Kr,Kb = map(int,input().split()) S = list(input()) A = [] for s in S: if s=='R': A.append(2) elif s=='B': A.append(1) else: A.append(0) R = [] B = [] for i,s in enumerate(S): if s=='R': R.append(i) if s=='B': B.append(i) S = A[:] def is_ok(X): T = [] for i,s in enumerate(S): if i in X: continue T.append(s) if any((T[i]==1)&(T[i]==T[i+Kb]) for i in range(len(T)-Kb)): return -1 if any((T[i]==2)&(T[i]==T[i+Kr]) for i in range(len(T)-Kr)): return -1 return len(T) Z = R+B ans = -1 for i in range(1<<20): X = [] for j in range(20): if (i>>j)&1: X.append(Z[j]) X = set(X) ans = max(ans,is_ok(X)) print(ans)