def mapping(string):

    return 1 if string == "L" else -1





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

s = list(map(mapping, eval(input())))



flips = []

for i in range(n - 1):

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

        flips.append(i + 1)



print((min(n - 1, n - 1 - len(flips) + 2 * k)))

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

s = eval(input())



flips = 0

for i in range(n - 1):

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

        flips += 1



print((min(n - 1, n - 1 - flips + 2 * k)))

def mapping(string):
    return 1 if string == "L" else -1


n, k = list(map(int, input().split()))
s = list(map(mapping, eval(input())))
flips = []
for i in range(n - 1):
    if s[i] != s[i + 1]:
        flips.append(i + 1)
print((min(n - 1, n - 1 - len(flips) + 2 * k)))

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

-def mapping(string): -    return 1 if string == "L" else -1 - - -s = list(map(mapping, eval(input()))) -flips = [] +s = eval(input()) +flips = 0 -        flips.append(i + 1) -print((min(n - 1, n - 1 - len(flips) + 2 * k))) +        flips += 1 +print((min(n - 1, n - 1 - flips + 2 * k)))