N, K = list(map(int, input().split()))

S = list(eval(input()))

T = []

pre = S[0]

cnt = 0

ans = -1

for i in range(N):

  if S[i] == pre:

    cnt += 1

    pass

  else:

    T += [pre]

    ans += cnt

    cnt = 0

    pre = S[i]



ans += cnt

T += [pre]

ans += min(K*2, len(T)-1)

print(ans)
N, K = list(map(int, input().split()))

S = list(eval(input()))



diff = []

ans = 0

for i in range(N-1):

  if S[i] != S[i+1]:

    diff += [i]

  else:

    ans += 1



print((min(N-1, ans+2*min(K, len(diff)))))
N, K = list(map(int, input().split()))
S = list(eval(input()))
T = []
pre = S[0]
cnt = 0
ans = -1
for i in range(N):
    if S[i] == pre:
        cnt += 1
        pass
    else:
        T += [pre]
        ans += cnt
        cnt = 0
        pre = S[i]
ans += cnt
T += [pre]
ans += min(K * 2, len(T) - 1)
print(ans)

N, K = list(map(int, input().split()))
S = list(eval(input()))
diff = []
ans = 0
for i in range(N - 1):
    if S[i] != S[i + 1]:
        diff += [i]
    else:
        ans += 1
print((min(N - 1, ans + 2 * min(K, len(diff)))))

-T = [] -pre = S[0] -cnt = 0 -ans = -1 -for i in range(N): -    if S[i] == pre: -        cnt += 1 -        pass +diff = [] +ans = 0 +for i in range(N - 1): +    if S[i] != S[i + 1]: +        diff += [i] -        T += [pre] -        ans += cnt -        cnt = 0 -        pre = S[i] -ans += cnt -T += [pre] -ans += min(K * 2, len(T) - 1) -print(ans) +        ans += 1 +print((min(N - 1, ans + 2 * min(K, len(diff)))))