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

S = eval(input())

counter = 0

RL = 0

RL_L = 0

RL_R = 0



if S[0] == 'L':

    RL_L += 1



if S[N-1] == 'R':

    RL_R += 1



for i in range(N-1):

    if S[i:i+2] == 'RL':

        counter += 1



if (counter - K) >= 0:

    counter -= K

    K = 0

else:

    K -= counter

    counter = 0

    RL = 0



if RL_L == 1 and K > 0:

    RL_L -= 1

    K -= 1



if RL_R == 1 and K > 0:

    RL_R -= 1

    K -= 1



ans = N - (counter*2 + RL_L + RL_R)



print((min(ans, N-1)))

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

S = eval(input())

counter = 0



ans = N-1



for i in range(N-1):

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

        ans -= 1



print((min(N-1, ans+2*K)))
N, K = list(map(int, input().split()))
S = eval(input())
counter = 0
RL = 0
RL_L = 0
RL_R = 0
if S[0] == "L":
    RL_L += 1
if S[N - 1] == "R":
    RL_R += 1
for i in range(N - 1):
    if S[i : i + 2] == "RL":
        counter += 1
if (counter - K) >= 0:
    counter -= K
    K = 0
else:
    K -= counter
    counter = 0
    RL = 0
if RL_L == 1 and K > 0:
    RL_L -= 1
    K -= 1
if RL_R == 1 and K > 0:
    RL_R -= 1
    K -= 1
ans = N - (counter * 2 + RL_L + RL_R)
print((min(ans, N - 1)))

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

-RL = 0 -RL_L = 0 -RL_R = 0 -if S[0] == "L": -    RL_L += 1 -if S[N - 1] == "R": -    RL_R += 1 +ans = N - 1 -    if S[i : i + 2] == "RL": -        counter += 1 -if (counter - K) >= 0: -    counter -= K -    K = 0 -else: -    K -= counter -    counter = 0 -    RL = 0 -if RL_L == 1 and K > 0: -    RL_L -= 1 -    K -= 1 -if RL_R == 1 and K > 0: -    RL_R -= 1 -    K -= 1 -ans = N - (counter * 2 + RL_L + RL_R) -print((min(ans, N - 1))) +    if S[i] != S[i + 1]: +        ans -= 1 +print((min(N - 1, ans + 2 * K)))