#include<iostream>
#include <stdio.h>
#include <vector>
using namespace std;
vector<int> vec;
vector<int>::iterator itr=vec.end();
int main(){int a;
while(cin>>a){
	if(a==0){itr=vec.end();itr--;cout<<*itr<<endl;
		vec.pop_back();
}else{
	vec.push_back(a);}}
	return 0;}
