def d_face_produces_unhappiness():

    N, K = [int(i) for i in input().split()]

    S = eval(input())

    before_char = S[0]

    t = []

    v = 0

    for s in S + '*':

        if s != before_char:

            t.append(v)

            v = 1

        else:

            v += 1

        before_char = s

    t.sort(reverse=True)

    for i in range(min(K, len(t))):

        t[i] += 2

    return min(sum([e - 1 for e in t]), N - 1)



print((d_face_produces_unhappiness()))
def d_face_produces_unhappiness():

    N, K = [int(i) for i in input().split()]

    S = eval(input())



    # 初期状態で幸福な人数 + 1回の操作で高々2人増やせる。ただしN-1人まで

    score_first = len([1 for i in range(N - 1) if S[i] == S[i + 1]])

    return min(score_first + 2 * K, N - 1)



print((d_face_produces_unhappiness()))
def d_face_produces_unhappiness():
    N, K = [int(i) for i in input().split()]
    S = eval(input())
    before_char = S[0]
    t = []
    v = 0
    for s in S + "*":
        if s != before_char:
            t.append(v)
            v = 1
        else:
            v += 1
        before_char = s
    t.sort(reverse=True)
    for i in range(min(K, len(t))):
        t[i] += 2
    return min(sum([e - 1 for e in t]), N - 1)


print((d_face_produces_unhappiness()))

def d_face_produces_unhappiness():
    N, K = [int(i) for i in input().split()]
    S = eval(input())
    # 初期状態で幸福な人数 + 1回の操作で高々2人増やせる。ただしN-1人まで
    score_first = len([1 for i in range(N - 1) if S[i] == S[i + 1]])
    return min(score_first + 2 * K, N - 1)


print((d_face_produces_unhappiness()))

-    before_char = S[0] -    t = [] -    v = 0 -    for s in S + "*": -        if s != before_char: -            t.append(v) -            v = 1 -        else: -            v += 1 -        before_char = s -    t.sort(reverse=True) -    for i in range(min(K, len(t))): -        t[i] += 2 -    return min(sum([e - 1 for e in t]), N - 1) +    # 初期状態で幸福な人数 + 1回の操作で高々2人増やせる。ただしN-1人まで +    score_first = len([1 for i in range(N - 1) if S[i] == S[i + 1]]) +    return min(score_first + 2 * K, N - 1)