let () =
  let rec read l p =
    try let n = read_int () in
        if n != 0 then read (n::l) p
        else read (List.tl l) ((List.hd l)::p)
    with End_of_file ->
      List.rev p |> List.iter (fun x -> print_int x |> print_newline)
  in read [] []
;;