type order = Push of int | Pop

let order_of_int n =
    match n with
    | 0 -> Pop
    | n -> Push(n)

let () =
    let cars = Stack.create () in
    try
        while true do
            let n     = read_int () in
            let order = order_of_int n in
            match order with
            | Push(n) -> Stack.push n cars
            | Pop     -> Printf.printf "%d\n" (Stack.pop cars)
        done
    with
        End_of_file -> ()