#include <iostream>
#include <stack>

int main ()
{
    std::stack<u_int> cars;
    u_int number;

    while(std::cin >> number){
        if(number != 0){
            cars.push(number);
        }else{
            std::cout << cars.top() << std::endl;
            cars.pop();
        }
    }
    
    return 0;
}