let () = Scanf.scanf "%d %d\n%s" @@ fun n k s ->
  let ss = Array.make n 1 in
  let ls = Array.make n 0 in
  for i = 1 to n - 1 do
    if s.[i - 1] = s.[i]
    then begin
      ss.(i) <- ss.(i - 1);
      ls.(ss.(i)) <- 1 + ls.(ss.(i))
    end else begin
      ss.(i) <- ss.(i - 1) + 1
    end
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 ls + min (ss.(n - 1) - 1) (2 * k)
