#include <iostream>
#include <vector>
using namespace std;

int main(){
	vector<int> car, exit;
	int n;
	
	while( cin >> n ){
		
		if(n==0){
			exit.push_back( car.back());
			car.pop_back();
		}else{
			car.push_back(n);
		}
		if(car.size()==0) break;
	}
	vector<int>::iterator it = exit.begin();

	while( it != exit.end() ){
		cout << *it << endl;
		++it;
	}
	return 0;
}