from collections import Counter

mod = 1000000007





def inverse(a):

    return pow(a, mod - 2, mod)





def usearch(x, a):

    lft = 0

    rgt = len(a) + 1

    while rgt - lft > 1:

        mid = (rgt + lft) // 2

        if a[mid] <= x:

            lft = mid

        else:

            rgt = mid

    return lft





def main():

    n, k = list(map(int, input().split()))

    s = eval(input())

    cnt = 0

    for i in range(n-1):

        if s[i] != s[i+1]:

            cnt += 1

    ans = n - 1 - cnt

    while cnt >= 2 and k > 0:

        ans += 2

        cnt -= 2

        k -= 1



    if k > 0 and cnt > 0:

        ans += 1



    print(ans)



main()

from collections import Counter

mod = 1000000007





def inverse(a):

    return pow(a, mod - 2, mod)





def usearch(x, a):

    lft = 0

    rgt = len(a) + 1

    while rgt - lft > 1:

        mid = (rgt + lft) // 2

        if a[mid] <= x:

            lft = mid

        else:

            rgt = mid

    return lft





def main():

    n, k = list(map(int, input().split()))

    s = eval(input())

    cnt = 0

    for i in range(n-1):

        if s[i] != s[i+1]:

            cnt += 1

    ans = n - 1 - cnt

    ans += k * 2

    ans = min(ans, n-1)

    print(ans)



main()

from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n, k = list(map(int, input().split()))
    s = eval(input())
    cnt = 0
    for i in range(n - 1):
        if s[i] != s[i + 1]:
            cnt += 1
    ans = n - 1 - cnt
    while cnt >= 2 and k > 0:
        ans += 2
        cnt -= 2
        k -= 1
    if k > 0 and cnt > 0:
        ans += 1
    print(ans)


main()

from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


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


main()

-    while cnt >= 2 and k > 0: -        ans += 2 -        cnt -= 2 -        k -= 1 -    if k > 0 and cnt > 0: -        ans += 1 +    ans += k * 2 +    ans = min(ans, n - 1)