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

s = eval(input())

ans = n - 1

for i in range(1, n):

    if s[i] != s[i - 1]:

        ans -= 1

print((min(n - 1, ans + 2 * k)))

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



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

s = read().rstrip().decode()

ans = n - 1

for bf, af in zip(s, s[1:]):

    if bf != af:

        ans -= 1

print((min(n - 1, ans + k * 2)))

n, k = list(map(int, input().split()))
s = eval(input())
ans = n - 1
for i in range(1, n):
    if s[i] != s[i - 1]:
        ans -= 1
print((min(n - 1, ans + 2 * k)))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n, k = list(map(int, readline().split()))
s = read().rstrip().decode()
ans = n - 1
for bf, af in zip(s, s[1:]):
    if bf != af:
        ans -= 1
print((min(n - 1, ans + k * 2)))

-n, k = list(map(int, input().split())) -s = eval(input()) +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +sys.setrecursionlimit(10**7) +n, k = list(map(int, readline().split())) +s = read().rstrip().decode() -for i in range(1, n): -    if s[i] != s[i - 1]: +for bf, af in zip(s, s[1:]): +    if bf != af: -print((min(n - 1, ans + 2 * k))) +print((min(n - 1, ans + k * 2)))