#include <iostream>
using namespace std;

int main() {
	int rail[10]={0};
	int n,i=0;
	while(cin>>n){
		if(n==0){
			cout<<rail[i-1]<<endl;
			i--;
			continue;
		}
		rail[i]=n;
		i++;
	}
	return 0;
}