#include<iostream>
#include<stack>
using namespace std;
int main()
{
	stack < int > s;
	int n;
	while (cin>>n){
		if (n == 0){
			int c = s.top();
			cout << c << endl;
			s.pop();
		}
		else{
			s.push(n);
		}
	}
}