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

S=eval(input())



ch=0

for i in range(N-1):

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

        ch+=1

print((min(N-1,N-ch-1+2*K)))


def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    mod=10**9+7

    N,K=MI()

    S=eval(input())

    

    ans=0

    now="A"

    for i in range(N):

        if S[i]==now:

            ans+=1

        now=S[i]

    

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

    print(ans)

        



main()

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

def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    mod = 10**9 + 7
    N, K = MI()
    S = eval(input())
    ans = 0
    now = "A"
    for i in range(N):
        if S[i] == now:
            ans += 1
        now = S[i]
    ans = min(N - 1, ans + K * 2)
    print(ans)


main()

-N, K = list(map(int, input().split())) -S = eval(input()) -ch = 0 -for i in range(N - 1): -    if S[i] != S[i + 1]: -        ch += 1 -print((min(N - 1, N - ch - 1 + 2 * K))) +def I(): +    return int(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def main(): +    mod = 10**9 + 7 +    N, K = MI() +    S = eval(input()) +    ans = 0 +    now = "A" +    for i in range(N): +        if S[i] == now: +            ans += 1 +        now = S[i] +    ans = min(N - 1, ans + K * 2) +    print(ans) + + +main()