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

s=eval(input())

ct=0

for i in range(n-1):

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

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

s=list(eval(input()))

ct=0

for i in range(n-1):

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

    ct+=1

x=ct

ct-=min(ct,k)

ct*=2

if s[0]==s[n-1]:

  ct+=1

elif s[0]=='L':

  if x<k:

    ct+=1

  else:

    ct+=2

else:

  if x<=k:

    ct+=1

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

n, k = list(map(int, input().split()))
s = list(eval(input()))
ct = 0
for i in range(n - 1):
    if s[i] == "R" and s[i + 1] == "L":
        ct += 1
x = ct
ct -= min(ct, k)
ct *= 2
if s[0] == s[n - 1]:
    ct += 1
elif s[0] == "L":
    if x < k:
        ct += 1
    else:
        ct += 2
else:
    if x <= k:
        ct += 1
print((n - ct))

-s = eval(input()) +s = list(eval(input())) -    if s[i] == s[i + 1]: +    if s[i] == "R" and s[i + 1] == "L": -print((min(ct + 2 * k, n - 1))) +x = ct +ct -= min(ct, k) +ct *= 2 +if s[0] == s[n - 1]: +    ct += 1 +elif s[0] == "L": +    if x < k: +        ct += 1 +    else: +        ct += 2 +else: +    if x <= k: +        ct += 1 +print((n - ct))