#include <iostream>
#include <stack>

using namespace std;

int main (void) {
    stack<int> st;
    int n;
    while (1) {
        cin >> n;
        if (cin.eof()) break;
        if (n != 0) {
            st.push(n);
        } else {
            cout << st.top() << endl;
            st.pop();
        }
    }
    return 0;
}