#include <iostream>

int main()
{
        int s[10], p = 0;
        int i;
        while(std::cin >> i)
                if(i)
                        s[p++]=i;
                else
                        std::cout << s[--p] << std::endl;
        return 0;
}