program face_produces_unhappiness
  implicit none
  integer :: n, k, nl = 0, nr = 0, i = 1, j = 1
  character(100000) :: s
  read(*,*) n, k
  read(*,*) s
  do while (i <= n)
    do while (s(j:j) == s(i:i))
      j = j+1
    end do
    if (s(i:i) == "L") then
      nl = nl+1
    else
      nr = nr+1
    end if
    i = j
  end do
  if (nl <= k .or. nr <= k) then
    write(*,'(i0)') n-1
  else
    write(*,'(i0)') n-nl-nr+2*k
  end if
end program face_produces_unhappiness