#include<iostream>
using namespace std;
 
int main(){
	int vehicle[10] = {}, count = 0, n;
	while(cin >> n){
		if(n != 0)
			vehicle[count++] = n;
		else
			cout << vehicle[--count] << endl;
	}
	return 0;
}
