from itertools import groupby

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

S = eval(input())

A = []



for i,j in groupby(S):

  A.append(len(list(j))-1)



print((min(N-1,sum(A)+2*K)))
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)))
from itertools import groupby

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

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)))

-from itertools import groupby +from itertools import * -    A.append(len(list(j)) - 1) +    A += [len(list(j)) - 1]