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+2))

    do i = 2, n+1
        if(s(i-1:i-1) == 'L')then
            cnum(i) = -1
        else
            cnum(i) = 1
        endif
    enddo
    cnum(1) = -1
    cnum(n+2) = 1
    ! print*, cnum
    do i = 2, n
        if (cnum(i) == cnum(i+1))then
            hap = hap + 1
            ! print*, i
        endif
    enddo



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

        if(cnum(i) ==  1)then
            ! print*, 'r'
            r = r + 1
        endif
    enddo

   


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

end program