//////////////////////////////////0013
#include <iostream>
using namespace std;

int main(){
	
	int num,in;
	while(cin>>in){
		if(in == 0){
			cout<<num<<endl;
		}else{
			in=num;
		}
	}
	return 0;
	
}