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

S = list(eval(input()))

count = 0

if N == 1:

    print('0')

    exit()

if S[0] == 'R' and S[1] == 'R':

    count += 1

if S[N - 2] == 'L' and S[N - 1] == 'L':

    count += 1

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

    if [S[i - 1], S[i]] == ['L', 'L'] or [S[i], S[i + 1]] == ['R', 'R']:

        count += 1

print((str(min(N - 1, count + K * 2))))
N, K = list(map(int, input().split()))

L = list(eval(input()))

L.insert(0, '')

L.append('')

num = 0

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

    if L[n] == 'L' and L[n - 1] == 'L':

        num += 1

    if L[n] == 'R' and L[n + 1] == 'R':

        num += 1

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

print((str(ans)))
N, K = list(map(int, input().split()))
S = list(eval(input()))
count = 0
if N == 1:
    print("0")
    exit()
if S[0] == "R" and S[1] == "R":
    count += 1
if S[N - 2] == "L" and S[N - 1] == "L":
    count += 1
for i in range(1, N - 1):
    if [S[i - 1], S[i]] == ["L", "L"] or [S[i], S[i + 1]] == ["R", "R"]:
        count += 1
print((str(min(N - 1, count + K * 2))))

N, K = list(map(int, input().split()))
L = list(eval(input()))
L.insert(0, "")
L.append("")
num = 0
for n in range(1, N + 1):
    if L[n] == "L" and L[n - 1] == "L":
        num += 1
    if L[n] == "R" and L[n + 1] == "R":
        num += 1
ans = min(num + K * 2, N - 1)
print((str(ans)))

-S = list(eval(input())) -count = 0 -if N == 1: -    print("0") -    exit() -if S[0] == "R" and S[1] == "R": -    count += 1 -if S[N - 2] == "L" and S[N - 1] == "L": -    count += 1 -for i in range(1, N - 1): -    if [S[i - 1], S[i]] == ["L", "L"] or [S[i], S[i + 1]] == ["R", "R"]: -        count += 1 -print((str(min(N - 1, count + K * 2)))) +L = list(eval(input())) +L.insert(0, "") +L.append("") +num = 0 +for n in range(1, N + 1): +    if L[n] == "L" and L[n - 1] == "L": +        num += 1 +    if L[n] == "R" and L[n + 1] == "R": +        num += 1 +ans = min(num + K * 2, N - 1) +print((str(ans)))