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

import numpy as np

S = np.array(list(eval(input())))

count = 0

if len(S) >= 2:

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

        count += 1

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

        count += 1

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

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

        count += 1

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

        count += 1

count += K * 2

print((min(count, N-1)))
import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, K = lr()

S = list(sr())

start = 0

for i in range(1, N):

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

        start += 1



answer = min(start + 2 * K, N-1)

print(answer)

# 45
N, K = list(map(int, input().split()))
import numpy as np

S = np.array(list(eval(input())))
count = 0
if len(S) >= 2:
    if S[0] == "R" and S[1] == "R":
        count += 1
    if S[-1] == "L" and S[-2] == "L":
        count += 1
for i in range(1, N - 1):
    if S[i] == "R" and S[i + 1] == "R":
        count += 1
    if S[i] == "L" and S[i - 1] == "L":
        count += 1
count += K * 2
print((min(count, N - 1)))

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
S = list(sr())
start = 0
for i in range(1, N):
    if S[i] == S[i - 1]:
        start += 1
answer = min(start + 2 * K, N - 1)
print(answer)
# 45

-N, K = list(map(int, input().split())) -import numpy as np +import sys -S = np.array(list(eval(input()))) -count = 0 -if len(S) >= 2: -    if S[0] == "R" and S[1] == "R": -        count += 1 -    if S[-1] == "L" and S[-2] == "L": -        count += 1 -for i in range(1, N - 1): -    if S[i] == "R" and S[i + 1] == "R": -        count += 1 -    if S[i] == "L" and S[i - 1] == "L": -        count += 1 -count += K * 2 -print((min(count, N - 1))) +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N, K = lr() +S = list(sr()) +start = 0 +for i in range(1, N): +    if S[i] == S[i - 1]: +        start += 1 +answer = min(start + 2 * K, N - 1) +print(answer) +# 45