def runlength(S):

    cnt = 1

    res = []

    for i in range(len(S)-1):

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

            cnt += 1

        else:

            res.append(cnt)

            cnt = 1



    res.append(cnt)

    return res





def main():

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

    S = eval(input())

    A = runlength(S)

    ans = 0

    for a in A:

        a -= 1

        ans += a

    ans = min(N-1, ans + 2 * K)

    print(ans)





if __name__ == "__main__":

    main()
def main():

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

    S = eval(input())

    cnt = 0

    for i in range(1,N):

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

            cnt += 1

    ans = min(N-1,cnt+2*K)

    print(ans)





if __name__ == "__main__":

    main()
def runlength(S):
    cnt = 1
    res = []
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            cnt += 1
        else:
            res.append(cnt)
            cnt = 1
    res.append(cnt)
    return res


def main():
    N, K = list(map(int, input().split()))
    S = eval(input())
    A = runlength(S)
    ans = 0
    for a in A:
        a -= 1
        ans += a
    ans = min(N - 1, ans + 2 * K)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    N, K = list(map(int, input().split()))
    S = eval(input())
    cnt = 0
    for i in range(1, N):
        if S[i] == S[i - 1]:
            cnt += 1
    ans = min(N - 1, cnt + 2 * K)
    print(ans)


if __name__ == "__main__":
    main()

-def runlength(S): -    cnt = 1 -    res = [] -    for i in range(len(S) - 1): -        if S[i] == S[i + 1]: -            cnt += 1 -        else: -            res.append(cnt) -            cnt = 1 -    res.append(cnt) -    return res - - -    A = runlength(S) -    ans = 0 -    for a in A: -        a -= 1 -        ans += a -    ans = min(N - 1, ans + 2 * K) +    cnt = 0 +    for i in range(1, N): +        if S[i] == S[i - 1]: +            cnt += 1 +    ans = min(N - 1, cnt + 2 * K)