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

S = eval(input())

T = []



g = S[0]

cnt = 0

for s in S:

    if s == g:

        cnt += 1

    else:

        T.append(cnt)

        cnt = 1

        g = s

else:

    T.append(cnt)





t = len(T)

for k in range(K):

    t -= 2



if t <= 1:

    print((N - 1))

else:

    print((N - t))

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

S = eval(input())

T = []



g = S[0]

cnt = 0

for s in S:

    if s == g:

        cnt += 1

    else:

        T.append(cnt)

        cnt = 1

        g = s

else:

    T.append(cnt)





print((N - max(1, len(T) - 2 * K)))

N, K = list(map(int, input().split()))
S = eval(input())
T = []
g = S[0]
cnt = 0
for s in S:
    if s == g:
        cnt += 1
    else:
        T.append(cnt)
        cnt = 1
        g = s
else:
    T.append(cnt)
t = len(T)
for k in range(K):
    t -= 2
if t <= 1:
    print((N - 1))
else:
    print((N - t))

N, K = list(map(int, input().split()))
S = eval(input())
T = []
g = S[0]
cnt = 0
for s in S:
    if s == g:
        cnt += 1
    else:
        T.append(cnt)
        cnt = 1
        g = s
else:
    T.append(cnt)
print((N - max(1, len(T) - 2 * K)))

-t = len(T) -for k in range(K): -    t -= 2 -if t <= 1: -    print((N - 1)) -else: -    print((N - t)) +print((N - max(1, len(T) - 2 * K)))