program main
    implicit none
    integer:: n, k, i, j, l,r
    integer,allocatable:: cnum(:)
    character(10**5):: s
    integer:: hap
    hap = 0
    read*, n, k
    read*, s
    
    allocate(cnum(n+1))

    do i = 1, n
        if(s(i:i) == 'L')then
            cnum(i) = -1
        else
            cnum(i) = 1
        endif
    enddo

    do i = 1,n-1
        if (cnum(i) == cnum(i+1)) hap = hap + 1
    enddo


    cnum(n+1) = cnum(1)*-1
    l = 0
    r = 0
    do i=1,n
        if (k <= 0)exit
        if (cnum(i) == cnum(i+1))cycle
        if(cnum(i) == -1)then
            ! print*, 'l'
            l = l + 1

        endif
        if (k <= 0)exit
        if(cnum(i) ==  1)then
            ! print*, 'r'
            r = r + 1


        endif
    enddo

   


    print*, hap + min(k,min(l,r))*2
    

end program