#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
 
using namespace std;

int main(){
    int n;
    int stack[10] = {0};
    int index = 0;
    while(cin >> n){
        switch(n){
            case 0 : {
                index--;
                cout << stack[index] << endl;
                break;
            }
            default : {
                stack[index] = n;
                index++;
                break;
            }
        }
    }
    return 0;
}