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

S = list(eval(input()))



ch = 0

ans = 0



if N != 1:

    for i in range(N):

        if i == 0:

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

                ch += 1

            if S[i] == S[i+1] == 'R':

                ans += 1

        elif i == N-1:

            if S[i] == S[i-1] == 'L':

                ans += 1

        else:

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

                ch += 1

            if S[i] == S[i+1] == 'R' or S[i] == S[i-1] == 'L':

                ans += 1



print((ans+min(K*2,ch)))

n,k = list(map(int,input().split()))

s = eval(input())



same = 0



for i in range(n-1):

    if s[i] == s[i+1]:

        same += 1



diff = n-1-same



print((same + min(2*k,diff)))

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

n, k = list(map(int, input().split()))
s = eval(input())
same = 0
for i in range(n - 1):
    if s[i] == s[i + 1]:
        same += 1
diff = n - 1 - same
print((same + min(2 * k, diff)))

-N, K = list(map(int, input().split())) -S = list(eval(input())) -ch = 0 -ans = 0 -if N != 1: -    for i in range(N): -        if i == 0: -            if S[i] != S[i + 1]: -                ch += 1 -            if S[i] == S[i + 1] == "R": -                ans += 1 -        elif i == N - 1: -            if S[i] == S[i - 1] == "L": -                ans += 1 -        else: -            if S[i] != S[i + 1]: -                ch += 1 -            if S[i] == S[i + 1] == "R" or S[i] == S[i - 1] == "L": -                ans += 1 -print((ans + min(K * 2, ch))) +n, k = list(map(int, input().split())) +s = eval(input()) +same = 0 +for i in range(n - 1): +    if s[i] == s[i + 1]: +        same += 1 +diff = n - 1 - same +print((same + min(2 * k, diff)))