N, K = list(map(int, input().split()))

S = eval(input())



Llist = []

Rlist = []

now = S[0]

cnt = 0



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

    if i < N and now == S[i]:

        cnt += 1

    else:

        if now == 'L':

            Llist.append(cnt)

        else:

            Rlist.append(cnt)

        if i < N:

            now = S[i]

            cnt = 0



length = min(len(Llist), len(Rlist))

ans = sum(Llist) + sum(Rlist)

#print(Llist, Rlist, length, ans)

if K == 0:

    print(ans)

else:

    for i in range(min(K, length)):

        length -= 1

        if len(Llist) != len(Rlist):

            ans += 2

        else:

            if length == 0:

                ans += 1

            else:

                ans += 2

    print(ans)
N, K = list(map(int, input().split()))

S = eval(input())



score = 0

for i in range(N-1):

    if S[i] == S[i+1]:

        score += 1



ans = min(score + 2*K, N-1)

print(ans)
N, K = list(map(int, input().split()))
S = eval(input())
Llist = []
Rlist = []
now = S[0]
cnt = 0
for i in range(1, N + 1):
    if i < N and now == S[i]:
        cnt += 1
    else:
        if now == "L":
            Llist.append(cnt)
        else:
            Rlist.append(cnt)
        if i < N:
            now = S[i]
            cnt = 0
length = min(len(Llist), len(Rlist))
ans = sum(Llist) + sum(Rlist)
# print(Llist, Rlist, length, ans)
if K == 0:
    print(ans)
else:
    for i in range(min(K, length)):
        length -= 1
        if len(Llist) != len(Rlist):
            ans += 2
        else:
            if length == 0:
                ans += 1
            else:
                ans += 2
    print(ans)

N, K = list(map(int, input().split()))
S = eval(input())
score = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        score += 1
ans = min(score + 2 * K, N - 1)
print(ans)

-Llist = [] -Rlist = [] -now = S[0] -cnt = 0 -for i in range(1, N + 1): -    if i < N and now == S[i]: -        cnt += 1 -    else: -        if now == "L": -            Llist.append(cnt) -        else: -            Rlist.append(cnt) -        if i < N: -            now = S[i] -            cnt = 0 -length = min(len(Llist), len(Rlist)) -ans = sum(Llist) + sum(Rlist) -# print(Llist, Rlist, length, ans) -if K == 0: -    print(ans) -else: -    for i in range(min(K, length)): -        length -= 1 -        if len(Llist) != len(Rlist): -            ans += 2 -        else: -            if length == 0: -                ans += 1 -            else: -                ans += 2 -    print(ans) +score = 0 +for i in range(N - 1): +    if S[i] == S[i + 1]: +        score += 1 +ans = min(score + 2 * K, N - 1) +print(ans)