from itertools import groupby



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

S = eval(input())

gnum = len(list(groupby(S)))

if gnum<=2*K-1:

  print((N-1))

else:

  print((min(N-(gnum-2*K),N-1)))
import itertools



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

S = eval(input())



gnum = 0

for key, elems in itertools.groupby(S):

    gnum += 1



k = K

while gnum > 1 and K > 0:

    if gnum != 2:

        gnum -= 2

    else:

        gnum -= 1

    K -= 1



if gnum == 1:

    print((N - 1))

else:

    print((N - gnum))

from itertools import groupby

N, K = list(map(int, input().split()))
S = eval(input())
gnum = len(list(groupby(S)))
if gnum <= 2 * K - 1:
    print((N - 1))
else:
    print((min(N - (gnum - 2 * K), N - 1)))

import itertools

N, K = list(map(int, input().split()))
S = eval(input())
gnum = 0
for key, elems in itertools.groupby(S):
    gnum += 1
k = K
while gnum > 1 and K > 0:
    if gnum != 2:
        gnum -= 2
    else:
        gnum -= 1
    K -= 1
if gnum == 1:
    print((N - 1))
else:
    print((N - gnum))

-from itertools import groupby +import itertools -gnum = len(list(groupby(S))) -if gnum <= 2 * K - 1: +gnum = 0 +for key, elems in itertools.groupby(S): +    gnum += 1 +k = K +while gnum > 1 and K > 0: +    if gnum != 2: +        gnum -= 2 +    else: +        gnum -= 1 +    K -= 1 +if gnum == 1: -    print((min(N - (gnum - 2 * K), N - 1))) +    print((N - gnum))