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

l=list(eval(input()))

s=l[0]

m=0

c=1

for i in range(1,n):

  if l[i]!=s:

    c+=1

    s=l[i]

if c//2<=k:

  print((n-1))

else:

  for i in range(1,n-1):

    if l[i]=="R":

      if l[i+1]=="R":

        m+=1

    if l[i]=="L":

      if l[i-1]=="L":

        m+=1

  if l[0]=="R" and l[0]==l[1]:

    m+=1

  if l[-1]=="L" and l[-2]==l[-1]:

    m+=1

  print((m+k*2))
n,k=list(map(int,input().split()))

l=list(eval(input()))

m=0

if n==1:

  print((0))

else:

  for i in range(1,n-1):

    if l[i]=="R":

      if l[i+1]=="R":

        m+=1

    if l[i]=="L":

      if l[i-1]=="L":

        m+=1

  if l[0]=="R" and l[0]==l[1]:

    m+=1

  if l[-1]=="L" and l[-2]==l[-1]:

    m+=1

  print((min(m+k*2,n-1)))
n, k = list(map(int, input().split()))
l = list(eval(input()))
s = l[0]
m = 0
c = 1
for i in range(1, n):
    if l[i] != s:
        c += 1
        s = l[i]
if c // 2 <= k:
    print((n - 1))
else:
    for i in range(1, n - 1):
        if l[i] == "R":
            if l[i + 1] == "R":
                m += 1
        if l[i] == "L":
            if l[i - 1] == "L":
                m += 1
    if l[0] == "R" and l[0] == l[1]:
        m += 1
    if l[-1] == "L" and l[-2] == l[-1]:
        m += 1
    print((m + k * 2))

n, k = list(map(int, input().split()))
l = list(eval(input()))
m = 0
if n == 1:
    print((0))
else:
    for i in range(1, n - 1):
        if l[i] == "R":
            if l[i + 1] == "R":
                m += 1
        if l[i] == "L":
            if l[i - 1] == "L":
                m += 1
    if l[0] == "R" and l[0] == l[1]:
        m += 1
    if l[-1] == "L" and l[-2] == l[-1]:
        m += 1
    print((min(m + k * 2, n - 1)))

-s = l[0] -c = 1 -for i in range(1, n): -    if l[i] != s: -        c += 1 -        s = l[i] -if c // 2 <= k: -    print((n - 1)) +if n == 1: +    print((0)) -    print((m + k * 2)) +    print((min(m + k * 2, n - 1)))