program main
  implicit none
  integer :: n, i, k, hap
  character(100000) :: s
  read (*, *) n, k
  read (*, *) s
  hap = 0
  do i = 1, n
    if (i == 1) then
      if (s(1:1) == "R" .and. s(2:2) == "R") hap = hap + 1
    else if (i == n) then
      if (s(n:n) == "L" .and. s(n - 1:n - 1) == "L") hap = hap + 1
    else
      if (s(i:i) == "L") then
        if (s(i - 1:i - 1) == "L") hap = hap + 1
      else
        if (s(i + 1:i + 1) == "R") hap = hap + 1
      end if
    end if
  end do
  write (*, "(i0)") min(n - 1, hap + 2 * k)
end program main
