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

s = eval(input())

score = 0

ans = 0

for i in range(n-1):

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

        score += 1



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

print(ans)

import sys



sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

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

    S = input().strip()



    cnt = 0

    for i in range(1, n):

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

            cnt += 1



    res = min(cnt + k * 2, n - 1)

    print(res)





if __name__ == '__main__':

    resolve()

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

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n, k = list(map(int, input().split()))
    S = input().strip()
    cnt = 0
    for i in range(1, n):
        if S[i - 1] == S[i]:
            cnt += 1
    res = min(cnt + k * 2, n - 1)
    print(res)


if __name__ == "__main__":
    resolve()

-n, k = list(map(int, input().split())) -s = eval(input()) -score = 0 -ans = 0 -for i in range(n - 1): -    if s[i] == s[i + 1]: -        score += 1 -ans = min(score + 2 * k, n - 1) -print(ans) +import sys + +sys.setrecursionlimit(10**7) +input = sys.stdin.readline +f_inf = float("inf") +mod = 10**9 + 7 + + +def resolve(): +    n, k = list(map(int, input().split())) +    S = input().strip() +    cnt = 0 +    for i in range(1, n): +        if S[i - 1] == S[i]: +            cnt += 1 +    res = min(cnt + k * 2, n - 1) +    print(res) + + +if __name__ == "__main__": +    resolve()