program sample
    implicit none
    character(100000)::s,t
    character::top,las
    integer(8) :: i,j,m,n,a,b,c,c1,k
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n,k
    read(*,*) s
    a=0
    b=0
    do i=1,n-1
        if(s(i:i+1) .eq. 'RL')then
            b=b+2
        end if
    end do
    c=0
    if(s(1:1) .eq. 'L' .and. s(n:n) .eq. 'R')then
        c=2
    elseif(s(1:1) .eq. 'L' .or. s(n:n) .eq. 'R')then
        c=1
    end if

    if(b/2<=k)then
        m=0
        k=k-b/2
        if(c==0)then
            c=1
        endif
        
    else
        m=b-2*k
        k=0
    end if
        
    if(k>0 .and. c==2)then
        c=1
    end if
    m=m+c

    write(*,*)n-m


   


 end program sample