#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    vector<int>a;
	int b;
	while(cin >> b){
		if(b==0){
			printf("%d\n",a[a.size()-1]);
			a.pop_back();
		}
		else{
			a.push_back(b);
		}
	}
    return 0;
}