#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    stack<int> st;
    queue<int> q;
    while (cin >> n)
    {
        if (n != 0)
        {
            st.push(n);
        }
        else
        {
            q.push(st.top());
            st.pop();
        }
    }
    while (q.size())
    {
        cout << q.front() << endl;
        q.pop();
    }
    return 0;
}
