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

s = input()

cd = 0

d = None

for l in s:

	if d != l:

		cd +=1

		d = l

score = 0

for u,v in zip(s,s[1:]):

	if u == v:

		score +=1



if cd > 2:

	t = min(k,((cd - 2)+1)/2)

	k -= t

	score += 2 * t 

	cd -= 2 * t

if cd == 2 and k:

	score +=1

	cd -= 1

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

score,d,cd = 0,None,0

s = input()

for i,l in enumerate(s):

	if d != l:

		cd +=1

		d = l

	if i and s[i-1] == s[i]:  score += 1





if cd > 2:

	t = min(k,((cd - 2)+1)/2)

	k -= t

	score += 2 * t 

	cd -= 2 * t

if cd == 2 and k:

	score +=1

	cd -= 1

print(score)

n, k = list(map(int, input().split()))
s = input()
cd = 0
d = None
for l in s:
    if d != l:
        cd += 1
        d = l
score = 0
for u, v in zip(s, s[1:]):
    if u == v:
        score += 1
if cd > 2:
    t = min(k, ((cd - 2) + 1) / 2)
    k -= t
    score += 2 * t
    cd -= 2 * t
if cd == 2 and k:
    score += 1
    cd -= 1
print(score)

n, k = list(map(int, input().split()))
score, d, cd = 0, None, 0
s = input()
for i, l in enumerate(s):
    if d != l:
        cd += 1
        d = l
    if i and s[i - 1] == s[i]:
        score += 1
if cd > 2:
    t = min(k, ((cd - 2) + 1) / 2)
    k -= t
    score += 2 * t
    cd -= 2 * t
if cd == 2 and k:
    score += 1
    cd -= 1
print(score)

+score, d, cd = 0, None, 0 -cd = 0 -d = None -for l in s: +for i, l in enumerate(s): -score = 0 -for u, v in zip(s, s[1:]): -    if u == v: +    if i and s[i - 1] == s[i]: