def main():

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

  s=eval(input())

  

  A=(('L','R'),('R','L'))

  B=[]

  Bappend=B.append

  cnt=0

  for i in range(n-1):

    tmp=(s[i],s[i+1])

    cnt+=1

    if tmp==A[0]:

      Bappend(cnt)

      cnt=0

    elif tmp==A[1]:

      Bappend(cnt)

      cnt=0

  cnt+=1

  Bappend(cnt)

  print((n-max(1,len(B)-2*k)))

  

if __name__=='__main__':

  main()
def main():

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

  s=eval(input())  

  B=s.count('RL')+s.count('LR')+1

  print((min(n-1,n-B+2*k)))  

if __name__=='__main__':

  main()
def main():
    n, k = list(map(int, input().split()))
    s = eval(input())
    A = (("L", "R"), ("R", "L"))
    B = []
    Bappend = B.append
    cnt = 0
    for i in range(n - 1):
        tmp = (s[i], s[i + 1])
        cnt += 1
        if tmp == A[0]:
            Bappend(cnt)
            cnt = 0
        elif tmp == A[1]:
            Bappend(cnt)
            cnt = 0
    cnt += 1
    Bappend(cnt)
    print((n - max(1, len(B) - 2 * k)))


if __name__ == "__main__":
    main()

def main():
    n, k = list(map(int, input().split()))
    s = eval(input())
    B = s.count("RL") + s.count("LR") + 1
    print((min(n - 1, n - B + 2 * k)))


if __name__ == "__main__":
    main()

-    A = (("L", "R"), ("R", "L")) -    B = [] -    Bappend = B.append -    cnt = 0 -    for i in range(n - 1): -        tmp = (s[i], s[i + 1]) -        cnt += 1 -        if tmp == A[0]: -            Bappend(cnt) -            cnt = 0 -        elif tmp == A[1]: -            Bappend(cnt) -            cnt = 0 -    cnt += 1 -    Bappend(cnt) -    print((n - max(1, len(B) - 2 * k))) +    B = s.count("RL") + s.count("LR") + 1 +    print((min(n - 1, n - B + 2 * k)))