N, K = [int(x) for x in input().split()]

S = str(eval(input()))



Unhappy = {}

Unhappy[1] = 0

Unhappy[2] = 0



for i in range(N):

    if i == 0:

        if S[i] == 'L':

            Unhappy[1] += 1

    if i == N - 1:

        if S[i] == 'R':

            Unhappy[1] += 1

    else:

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

            Unhappy[2] += 1



if Unhappy[1] == 0:

    act = min(K, Unhappy[2] - 1)

    K -= act

    Unhappy[2] -= act

    if K != 0:

        K -= 1

        Unhappy[2] -= 1

        Unhappy[1] += 1

else:

    act = min(K, Unhappy[2])

    K -= act

    Unhappy[2] -= act

    if Unhappy[1] == 2 and K != 0:

        K -= 1

        Unhappy[1] -= 1



print((N - Unhappy[1] - Unhappy[2] * 2))
N, K = [int(x) for x in input().split()]

S = str(eval(input()))



a=0

for i in range(N - 1):

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

  a += 1

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

print(b)
N, K = [int(x) for x in input().split()]
S = str(eval(input()))
Unhappy = {}
Unhappy[1] = 0
Unhappy[2] = 0
for i in range(N):
    if i == 0:
        if S[i] == "L":
            Unhappy[1] += 1
    if i == N - 1:
        if S[i] == "R":
            Unhappy[1] += 1
    else:
        if S[i] == "R" and S[i + 1] == "L":
            Unhappy[2] += 1
if Unhappy[1] == 0:
    act = min(K, Unhappy[2] - 1)
    K -= act
    Unhappy[2] -= act
    if K != 0:
        K -= 1
        Unhappy[2] -= 1
        Unhappy[1] += 1
else:
    act = min(K, Unhappy[2])
    K -= act
    Unhappy[2] -= act
    if Unhappy[1] == 2 and K != 0:
        K -= 1
        Unhappy[1] -= 1
print((N - Unhappy[1] - Unhappy[2] * 2))

N, K = [int(x) for x in input().split()]
S = str(eval(input()))
a = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        a += 1
b = min(N - 1, a + 2 * K)
print(b)

-Unhappy = {} -Unhappy[1] = 0 -Unhappy[2] = 0 -for i in range(N): -    if i == 0: -        if S[i] == "L": -            Unhappy[1] += 1 -    if i == N - 1: -        if S[i] == "R": -            Unhappy[1] += 1 -    else: -        if S[i] == "R" and S[i + 1] == "L": -            Unhappy[2] += 1 -if Unhappy[1] == 0: -    act = min(K, Unhappy[2] - 1) -    K -= act -    Unhappy[2] -= act -    if K != 0: -        K -= 1 -        Unhappy[2] -= 1 -        Unhappy[1] += 1 -else: -    act = min(K, Unhappy[2]) -    K -= act -    Unhappy[2] -= act -    if Unhappy[1] == 2 and K != 0: -        K -= 1 -        Unhappy[1] -= 1 -print((N - Unhappy[1] - Unhappy[2] * 2)) +a = 0 +for i in range(N - 1): +    if S[i] == S[i + 1]: +        a += 1 +b = min(N - 1, a + 2 * K) +print(b)