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 1 s.[0] 0 in
        let rest_k = k - min (a / 2) k in
        let rest_a = a - 2 * (k - rest_k) in
        let rest_a = if rest_a = 1 && rest_k > 0 then rest_a - 1 else rest_a in

        let r = n - (rest_a + 1) in
        Printf.printf "%d\n" r
    in
    main ()