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

s = eval(input())

if len(s) == 1:

    print((0))

    exit()



ans = 0

c = 0

for i in range(1,n):

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

        ans += 1

    else:

        c += 1



if c == 1:

    print((n-1))

    exit()





t = -1

left = s[0]

q = -1

for i in range(1,n):

    if s[i] != left:

        t += 1

        left = s[i]

    if t == 1 and k > 0:

        k -= 1

        ans += 2

        t = -1



if t == 0 and k > 0:

    ans += 1

print(ans)

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

s = eval(input())

ans = 0

for i in range(1,n):

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

        ans += 1



print((min(ans + 2*k,n-1)))
n, k = list(map(int, input().split()))
s = eval(input())
if len(s) == 1:
    print((0))
    exit()
ans = 0
c = 0
for i in range(1, n):
    if s[i] == s[i - 1]:
        ans += 1
    else:
        c += 1
if c == 1:
    print((n - 1))
    exit()
t = -1
left = s[0]
q = -1
for i in range(1, n):
    if s[i] != left:
        t += 1
        left = s[i]
    if t == 1 and k > 0:
        k -= 1
        ans += 2
        t = -1
if t == 0 and k > 0:
    ans += 1
print(ans)

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

-if len(s) == 1: -    print((0)) -    exit() -c = 0 -    else: -        c += 1 -if c == 1: -    print((n - 1)) -    exit() -t = -1 -left = s[0] -q = -1 -for i in range(1, n): -    if s[i] != left: -        t += 1 -        left = s[i] -    if t == 1 and k > 0: -        k -= 1 -        ans += 2 -        t = -1 -if t == 0 and k > 0: -    ans += 1 -print(ans) +print((min(ans + 2 * k, n - 1)))