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

S = list(eval(input()))



first = S[0]

flg = False

for index in range(1,N):

    if S[index] == first and flg:

        flg = False

        K -= 1

    elif S[index] != first:

        S[index] = first

        flg = True

    

    if K == 0:

        break

 

count = 0

for index in range(1,N):

    if S[index] == S[index -1]:

        count += 1

    



print(count)





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

B = eval(input())



happy = 0

for n in range(N - 1):

     if B[n] == B[n + 1]:

            happy += 1



print((N -1 if happy + K*2 > N-1 else happy + K*2))

    
N, K = list(map(int, input().split(" ")))
S = list(eval(input()))
first = S[0]
flg = False
for index in range(1, N):
    if S[index] == first and flg:
        flg = False
        K -= 1
    elif S[index] != first:
        S[index] = first
        flg = True
    if K == 0:
        break
count = 0
for index in range(1, N):
    if S[index] == S[index - 1]:
        count += 1
print(count)

N, K = list(map(int, input().split()))
B = eval(input())
happy = 0
for n in range(N - 1):
    if B[n] == B[n + 1]:
        happy += 1
print((N - 1 if happy + K * 2 > N - 1 else happy + K * 2))

-N, K = list(map(int, input().split(" "))) -S = list(eval(input())) -first = S[0] -flg = False -for index in range(1, N): -    if S[index] == first and flg: -        flg = False -        K -= 1 -    elif S[index] != first: -        S[index] = first -        flg = True -    if K == 0: -        break -count = 0 -for index in range(1, N): -    if S[index] == S[index - 1]: -        count += 1 -print(count) +N, K = list(map(int, input().split())) +B = eval(input()) +happy = 0 +for n in range(N - 1): +    if B[n] == B[n + 1]: +        happy += 1 +print((N - 1 if happy + K * 2 > N - 1 else happy + K * 2))