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

s="R"+eval(input())+"L"

now="X"

l=[]

le=None

for i in range(n+2):

    if now!=s[i]:

        l.append(le)

        now=s[i]

        le=1

    else:

        le+=1

l.append(le)

l=l[1:]

nn=len(l)

lr=[]

ll=[]

su=0

for i in range(0,nn,2):

    lr.append(l[i])

    su+=l[i]-1

for i in range(1,nn,2):

    ll.append(l[i])

    su+=l[i]-1

if lr[0]>1:

    su-=1

if ll[-1]>1:

    su-=1

maxgain=n-1-su

if 2*k<maxgain:

    print((su+2*k))

else:

    print((su+maxgain))

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

s=eval(input())

rl=s.count("RL")

lr=s.count("LR")

cnt=0

for i in range(n):

    if (i>0 and s[i]=="L" and s[i-1]=="L") or (i<n-1 and s[i]=="R" and s[i+1]=="R"):

        cnt+=1

for i in range(k):

    if min(rl,lr)>0:

        cnt+=2

        rl-=1

        lr-=1

    elif rl>0:

        cnt+=1

        rl-=1

    elif lr>0:

        cnt+=1

        lr-=1

    else:

        break

print(cnt)
n, k = list(map(int, input().split()))
s = "R" + eval(input()) + "L"
now = "X"
l = []
le = None
for i in range(n + 2):
    if now != s[i]:
        l.append(le)
        now = s[i]
        le = 1
    else:
        le += 1
l.append(le)
l = l[1:]
nn = len(l)
lr = []
ll = []
su = 0
for i in range(0, nn, 2):
    lr.append(l[i])
    su += l[i] - 1
for i in range(1, nn, 2):
    ll.append(l[i])
    su += l[i] - 1
if lr[0] > 1:
    su -= 1
if ll[-1] > 1:
    su -= 1
maxgain = n - 1 - su
if 2 * k < maxgain:
    print((su + 2 * k))
else:
    print((su + maxgain))

n, k = list(map(int, input().split()))
s = eval(input())
rl = s.count("RL")
lr = s.count("LR")
cnt = 0
for i in range(n):
    if (i > 0 and s[i] == "L" and s[i - 1] == "L") or (
        i < n - 1 and s[i] == "R" and s[i + 1] == "R"
    ):
        cnt += 1
for i in range(k):
    if min(rl, lr) > 0:
        cnt += 2
        rl -= 1
        lr -= 1
    elif rl > 0:
        cnt += 1
        rl -= 1
    elif lr > 0:
        cnt += 1
        lr -= 1
    else:
        break
print(cnt)

-s = "R" + eval(input()) + "L" -now = "X" -l = [] -le = None -for i in range(n + 2): -    if now != s[i]: -        l.append(le) -        now = s[i] -        le = 1 +s = eval(input()) +rl = s.count("RL") +lr = s.count("LR") +cnt = 0 +for i in range(n): +    if (i > 0 and s[i] == "L" and s[i - 1] == "L") or ( +        i < n - 1 and s[i] == "R" and s[i + 1] == "R" +    ): +        cnt += 1 +for i in range(k): +    if min(rl, lr) > 0: +        cnt += 2 +        rl -= 1 +        lr -= 1 +    elif rl > 0: +        cnt += 1 +        rl -= 1 +    elif lr > 0: +        cnt += 1 +        lr -= 1 -        le += 1 -l.append(le) -l = l[1:] -nn = len(l) -lr = [] -ll = [] -su = 0 -for i in range(0, nn, 2): -    lr.append(l[i]) -    su += l[i] - 1 -for i in range(1, nn, 2): -    ll.append(l[i]) -    su += l[i] - 1 -if lr[0] > 1: -    su -= 1 -if ll[-1] > 1: -    su -= 1 -maxgain = n - 1 - su -if 2 * k < maxgain: -    print((su + 2 * k)) -else: -    print((su + maxgain)) +        break +print(cnt)