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

s="#"+eval(input())+"#"

ans=0

for i in range(1,n+1):

    if s[i]=="R" and s[i+1]=="R":

        ans+=1

    if s[i]=="L" and s[i-1]=="L":

        ans+=1

a=max(s.count("LR"),s.count("RL"))

if k>=a:

    ans=n-1

else:

    ans+=2*k

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

s=eval(input())

a=0

for i in range(1,n):

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

        a+=1

print((min(n-1,a+2*k)))
n, k = list(map(int, input().split()))
s = "#" + eval(input()) + "#"
ans = 0
for i in range(1, n + 1):
    if s[i] == "R" and s[i + 1] == "R":
        ans += 1
    if s[i] == "L" and s[i - 1] == "L":
        ans += 1
a = max(s.count("LR"), s.count("RL"))
if k >= a:
    ans = n - 1
else:
    ans += 2 * k
print(ans)

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

-s = "#" + eval(input()) + "#" -ans = 0 -for i in range(1, n + 1): -    if s[i] == "R" and s[i + 1] == "R": -        ans += 1 -    if s[i] == "L" and s[i - 1] == "L": -        ans += 1 -a = max(s.count("LR"), s.count("RL")) -if k >= a: -    ans = n - 1 -else: -    ans += 2 * k -print(ans) +s = eval(input()) +a = 0 +for i in range(1, n): +    if s[i] == s[i - 1]: +        a += 1 +print((min(n - 1, a + 2 * k)))