let get_citation l =
  let rec loop p c = function
      [] -> p::c
    | hd::tl ->if (snd p)+1 = hd then
                  loop (fst p, hd) c tl
                else
                  loop (hd,hd) (p::c) tl
  in loop (-1,-1) [] l
;;

let print_citation t =
  if (fst t) = (snd t) then
    Printf.printf "%d" (fst t)
  else
    Printf.printf "%d-%d" (fst t) (snd t)
;;

let () =
  let rec read () =
    let n = read_int () in
    if n != 0 then
      begin
        let l = read_line ()
                |> Str.split (Str.regexp " ")
                |> List.map int_of_string in
        let ct = get_citation l |> List.rev in
        let len = List.length ct in
        List.iteri
          (fun i x ->
            if fst x != -1 then begin
                print_citation x;
                if i = len-1 then Printf.printf "\n" else Printf.printf " "
              end
          ) ct;
        read ()
      end
  in read ()
;;