#include<iostream>
#include<stack>

using namespace std;

int main()
{
	stack<int> hako;
	int temp[100];
	int t, i = 0;
	
	cin >> t;
	
	hako.push(t);
	while(hako.size() != 0){
		cin >> t;
		if(t == 0){
			temp[i] = hako.top();
			hako.pop();
			i++;
		}
		else{
			hako.push(t);
		}
	}
	
	for(int j = 0; j < i; j++){
		cout << temp[j] << endl;
	}
	
}
			