let () =
    let main () =
        let n, k = Scanf.sscanf (read_line ()) "%d %d" (fun n k -> n, k) in
        let s = read_line () in
        let rec loop i prev acc =
            if i = n then acc else
                if prev = s.[i] then loop (i + 1) s.[i] acc else
                        loop (i + 1) s.[i] (acc + 1)
        in
        let a = loop 0 'R' 0 in
        let r = min (n - a + 2 * k) (n - 1) in
        Printf.printf "%d\n" r
    in
    main ()