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

s=eval(input())

t=s[0]

c=[-1,1][s[0]=="R"]

d=[0]



for i in range(1,n):

    if t!=s[i]:

        d.append(c)

        c=0

    t=s[i]

    c+=[-1,1][s[i]=="R"]

d.append(c)

c=len(d)



if c>2:

    for i in range(1,k+1):

        if i*2>=c: break

        d[i*2]*=-1

chk=0

ans=0

for i in d:

    if (i>0 and chk>0) or (i<0 and chk<0):

        chk+=i

    else:

        if chk!=0: ans+=abs(chk)-1

        chk=i



print((ans+(abs(chk)-1)))

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

s=eval(input())

t=s[0]

c=[-1,1][s[0]=="R"]

d=[]



for i in range(1,n):

    if t!=s[i]:

        d.append(c)

        c=0

    t=s[i]

    c+=[-1,1][s[i]=="R"]

d.append(c)

c=len(d)

for i in range(k):

    if i*2+1>=c: break

    d[i*2+1]*=-1

chk=0

ans=0

for i in d:

    if (i>0 and chk>0) or (i<0 and chk<0):

        chk+=i

    else:

        if chk!=0: ans+=abs(chk)-1

        chk=i



print((ans+(abs(chk)-1)))
n, k = list(map(int, input().split()))
s = eval(input())
t = s[0]
c = [-1, 1][s[0] == "R"]
d = [0]
for i in range(1, n):
    if t != s[i]:
        d.append(c)
        c = 0
    t = s[i]
    c += [-1, 1][s[i] == "R"]
d.append(c)
c = len(d)
if c > 2:
    for i in range(1, k + 1):
        if i * 2 >= c:
            break
        d[i * 2] *= -1
chk = 0
ans = 0
for i in d:
    if (i > 0 and chk > 0) or (i < 0 and chk < 0):
        chk += i
    else:
        if chk != 0:
            ans += abs(chk) - 1
        chk = i
print((ans + (abs(chk) - 1)))

n, k = list(map(int, input().split()))
s = eval(input())
t = s[0]
c = [-1, 1][s[0] == "R"]
d = []
for i in range(1, n):
    if t != s[i]:
        d.append(c)
        c = 0
    t = s[i]
    c += [-1, 1][s[i] == "R"]
d.append(c)
c = len(d)
for i in range(k):
    if i * 2 + 1 >= c:
        break
    d[i * 2 + 1] *= -1
chk = 0
ans = 0
for i in d:
    if (i > 0 and chk > 0) or (i < 0 and chk < 0):
        chk += i
    else:
        if chk != 0:
            ans += abs(chk) - 1
        chk = i
print((ans + (abs(chk) - 1)))

-d = [0] +d = [] -if c > 2: -    for i in range(1, k + 1): -        if i * 2 >= c: -            break -        d[i * 2] *= -1 +for i in range(k): +    if i * 2 + 1 >= c: +        break +    d[i * 2 + 1] *= -1