from math import ceil

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

S = 'x' + eval(input()) + 'x'



ans = 0

X = ''

ns = ''



for i, s in enumerate(S[1:-1], start=1):

    if s == 'L':

        if S[i - 1] == 'L':

            ans += 1

        else:

            X += s



    else:

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

            ans += 1

        else:

            X += s





target = 'L' if X[0] == 'R' else 'R'

k_cnt = 0

for i, x in enumerate(X):

    if x == target and k_cnt < K:

        k_cnt += 1

        if i == len(X) - 1:

            ans += 1

        else:

            ans += 2



print(ans)

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

S = eval(input())



ans = 0

for i in range(N):

    if S[i] == 'L':

        if i - 1 < 0:

            continue

        if S[i - 1] == 'L':

            ans += 1

    else:

        if i + 1 >= N:

            continue

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

            ans += 1





X = (len([s for s in S.split('L') if s != '']) + len([s for s in S.split('R') if s != '']))

ans += min(X, K) * 2

print((min(ans, N - 1)))

from math import ceil

N, K = list(map(int, input().split()))
S = "x" + eval(input()) + "x"
ans = 0
X = ""
ns = ""
for i, s in enumerate(S[1:-1], start=1):
    if s == "L":
        if S[i - 1] == "L":
            ans += 1
        else:
            X += s
    else:
        if S[i + 1] == "R":
            ans += 1
        else:
            X += s
target = "L" if X[0] == "R" else "R"
k_cnt = 0
for i, x in enumerate(X):
    if x == target and k_cnt < K:
        k_cnt += 1
        if i == len(X) - 1:
            ans += 1
        else:
            ans += 2
print(ans)

N, K = list(map(int, input().split()))
S = eval(input())
ans = 0
for i in range(N):
    if S[i] == "L":
        if i - 1 < 0:
            continue
        if S[i - 1] == "L":
            ans += 1
    else:
        if i + 1 >= N:
            continue
        if S[i + 1] == "R":
            ans += 1
X = len([s for s in S.split("L") if s != ""]) + len(
    [s for s in S.split("R") if s != ""]
)
ans += min(X, K) * 2
print((min(ans, N - 1)))

-from math import ceil - -S = "x" + eval(input()) + "x" +S = eval(input()) -X = "" -ns = "" -for i, s in enumerate(S[1:-1], start=1): -    if s == "L": +for i in range(N): +    if S[i] == "L": +        if i - 1 < 0: +            continue -        else: -            X += s +        if i + 1 >= N: +            continue -        else: -            X += s -target = "L" if X[0] == "R" else "R" -k_cnt = 0 -for i, x in enumerate(X): -    if x == target and k_cnt < K: -        k_cnt += 1 -        if i == len(X) - 1: -            ans += 1 -        else: -            ans += 2 -print(ans) +X = len([s for s in S.split("L") if s != ""]) + len( +    [s for s in S.split("R") if s != ""] +) +ans += min(X, K) * 2 +print((min(ans, N - 1)))