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

S=list(input())



L=[]



now=None

for i,s in enumerate(S):

	if i==0:

		now=s

		cnt=1

	elif now==s:

		cnt+=1

	elif now!=s:

		L.append([now,cnt])

		cnt=1

		now=s

else:

	L.append([now,cnt])	



l=len(L)



for i in range(1,min(K*2,l),2):

	s=L[i][0]

	if s=="L": L[i][0]="R"

	elif s=="R": L[i][0]="L"





ans=0

prev=None

for t in L:

	s=t[0]

	cnt=t[1]

	if prev is None:

		prev=s

		lcnt=cnt

	else:

		if prev==s:

			lcnt+=cnt

		elif prev!=s:

			ans+=(lcnt-1)

			lcnt=cnt

		prev=s

else:

	ans+=(lcnt-1)

	

print(ans)
# -*- coding: utf-8 -*-

import sys

N,K=list(map(int, sys.stdin.readline().split()))

S=sys.stdin.readline().strip()

L=[]

cnt=0

for i,x in enumerate(S):

    if i==0:

        cnt+=1

        prev=x

    else:

        if prev==x: #前の文字と今の文字が同じ

            cnt+=1

        else:       #前の文字と今の文字が異なる

            L.append(cnt)

            cnt=1

        prev=x

else:

    L.append(cnt)



print(sum(L)-max(1,len(L)-2*K))

N, K = list(map(int, input().split()))
S = list(input())
L = []
now = None
for i, s in enumerate(S):
    if i == 0:
        now = s
        cnt = 1
    elif now == s:
        cnt += 1
    elif now != s:
        L.append([now, cnt])
        cnt = 1
        now = s
else:
    L.append([now, cnt])
l = len(L)
for i in range(1, min(K * 2, l), 2):
    s = L[i][0]
    if s == "L":
        L[i][0] = "R"
    elif s == "R":
        L[i][0] = "L"
ans = 0
prev = None
for t in L:
    s = t[0]
    cnt = t[1]
    if prev is None:
        prev = s
        lcnt = cnt
    else:
        if prev == s:
            lcnt += cnt
        elif prev != s:
            ans += lcnt - 1
            lcnt = cnt
        prev = s
else:
    ans += lcnt - 1
print(ans)

# -*- coding: utf-8 -*-
import sys

N, K = list(map(int, sys.stdin.readline().split()))
S = sys.stdin.readline().strip()
L = []
cnt = 0
for i, x in enumerate(S):
    if i == 0:
        cnt += 1
        prev = x
    else:
        if prev == x:  # 前の文字と今の文字が同じ
            cnt += 1
        else:  # 前の文字と今の文字が異なる
            L.append(cnt)
            cnt = 1
        prev = x
else:
    L.append(cnt)
print(sum(L) - max(1, len(L) - 2 * K))

-N, K = list(map(int, input().split())) -S = list(input()) +# -*- coding: utf-8 -*- +import sys + +N, K = list(map(int, sys.stdin.readline().split())) +S = sys.stdin.readline().strip() -now = None -for i, s in enumerate(S): +cnt = 0 +for i, x in enumerate(S): -        now = s -        cnt = 1 -    elif now == s: -    elif now != s: -        L.append([now, cnt]) -        cnt = 1 -        now = s +        prev = x +    else: +        if prev == x:  # 前の文字と今の文字が同じ +            cnt += 1 +        else:  # 前の文字と今の文字が異なる +            L.append(cnt) +            cnt = 1 +        prev = x -    L.append([now, cnt]) -l = len(L) -for i in range(1, min(K * 2, l), 2): -    s = L[i][0] -    if s == "L": -        L[i][0] = "R" -    elif s == "R": -        L[i][0] = "L" -ans = 0 -prev = None -for t in L: -    s = t[0] -    cnt = t[1] -    if prev is None: -        prev = s -        lcnt = cnt -    else: -        if prev == s: -            lcnt += cnt -        elif prev != s: -            ans += lcnt - 1 -            lcnt = cnt -        prev = s -else: -    ans += lcnt - 1 -print(ans) +    L.append(cnt) +print(sum(L) - max(1, len(L) - 2 * K))