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

int main(){
	vector<int> train;
	int n;
	while(cin >> n){
		if(n!=0){
			train.push_back(n);
		}
		else{
			cout << train.back();
			train.pop_back();
		}
	}
	return 0;
}