from itertools import *

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

S = eval(input())

A = []



for i,j in groupby(S):

  A+=[len(list(j))-1]



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

S = eval(input())

print((min(sum(S[n]==S[n+1] for n in range(N-1))+2*K,N-1)))
from itertools import *

N, K = list(map(int, input().split()))
S = eval(input())
A = []
for i, j in groupby(S):
    A += [len(list(j)) - 1]
print((min(N - 1, sum(A) + 2 * K)))

N, K = list(map(int, input().split()))
S = eval(input())
print((min(sum(S[n] == S[n + 1] for n in range(N - 1)) + 2 * K, N - 1)))

-from itertools import * - -A = [] -for i, j in groupby(S): -    A += [len(list(j)) - 1] -print((min(N - 1, sum(A) + 2 * K))) +print((min(sum(S[n] == S[n + 1] for n in range(N - 1)) + 2 * K, N - 1)))