# -*- coding: utf-8 -*-

# https://atcoder.jp/contests/abc140/tasks/abc140_d



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

S = input().strip()



happiness = 0

for idx in range(1, N):

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

        happiness += 1



# 一人しか幸せにできないときがあるか?

#

# あっ...これは不要なのでは...

# 単に後述の幸せの最大値で丸めればよいのでは

# always_two_happiness = S[0] == S[-1]



# 幸せの最大値

max_happiness = N - 1



for i in range(K):

    happiness += 2



print((min(happiness, max_happiness)))

#!/usr/bin/env python3

# -*- coding: utf-8 -*-



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

S = input().strip()



# 初期の幸せ度を調べる

happiness = 0

previous_face = S[0]

for i in range(1, N):

    if S[i] == previous_face:

        happiness += 1

    else:

        previous_face = S[i]



# 並べ替え後の幸せ度

happiness = happiness + 2 * K

if N - 1 < happiness:

    happiness = N - 1



# 出力

print(happiness)

# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc140/tasks/abc140_d
N, K = list(map(int, input().split()))
S = input().strip()
happiness = 0
for idx in range(1, N):
    if S[idx] == S[idx - 1]:
        happiness += 1
# 一人しか幸せにできないときがあるか?
#
# あっ...これは不要なのでは...
# 単に後述の幸せの最大値で丸めればよいのでは
# always_two_happiness = S[0] == S[-1]
# 幸せの最大値
max_happiness = N - 1
for i in range(K):
    happiness += 2
print((min(happiness, max_happiness)))

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = list(map(int, input().split()))
S = input().strip()
# 初期の幸せ度を調べる
happiness = 0
previous_face = S[0]
for i in range(1, N):
    if S[i] == previous_face:
        happiness += 1
    else:
        previous_face = S[i]
# 並べ替え後の幸せ度
happiness = happiness + 2 * K
if N - 1 < happiness:
    happiness = N - 1
# 出力
print(happiness)

+#!/usr/bin/env python3 -# https://atcoder.jp/contests/abc140/tasks/abc140_d +# 初期の幸せ度を調べる -for idx in range(1, N): -    if S[idx] == S[idx - 1]: +previous_face = S[0] +for i in range(1, N): +    if S[i] == previous_face: -# 一人しか幸せにできないときがあるか? -# -# あっ...これは不要なのでは... -# 単に後述の幸せの最大値で丸めればよいのでは -# always_two_happiness = S[0] == S[-1] -# 幸せの最大値 -max_happiness = N - 1 -for i in range(K): -    happiness += 2 -print((min(happiness, max_happiness))) +    else: +        previous_face = S[i] +# 並べ替え後の幸せ度 +happiness = happiness + 2 * K +if N - 1 < happiness: +    happiness = N - 1 +# 出力 +print(happiness)