#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	queue<int> leave;
	stack<int> waiting;
	int n;
	while(scanf("%d",&n)==1){
		if(n==0){
			leave.push(waiting.top());
			waiting.pop();
		}else{
			waiting.push(n);
		}
	}
	while(!leave.empty()){
		cout<<leave.front()<<endl;
		leave.pop();
	}
	return 0;
}