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

s = [1 if ele=="L" else 0 for ele in eval(input())]



if s[0]==0:

    s=[(1-ele) for ele in s]



before = s[0]

cnt=0

for si in s:

    if si != before:

        cnt += 1

    before = si



score_max = len(s)-1

print((min(score_max, score_max-cnt+k*2)))
n,k = list(map(int,input().split()))

s = [1 if ele=="L" else 0 for ele in eval(input())]



before = s[0]

cnt=0



for si in s:

    if si != before:

        cnt += 1

    before = si



score_max = len(s)-1

print((min(score_max, score_max-cnt+k*2)))
n, k = list(map(int, input().split()))
s = [1 if ele == "L" else 0 for ele in eval(input())]
if s[0] == 0:
    s = [(1 - ele) for ele in s]
before = s[0]
cnt = 0
for si in s:
    if si != before:
        cnt += 1
    before = si
score_max = len(s) - 1
print((min(score_max, score_max - cnt + k * 2)))

n, k = list(map(int, input().split()))
s = [1 if ele == "L" else 0 for ele in eval(input())]
before = s[0]
cnt = 0
for si in s:
    if si != before:
        cnt += 1
    before = si
score_max = len(s) - 1
print((min(score_max, score_max - cnt + k * 2)))

-if s[0] == 0: -    s = [(1 - ele) for ele in s]