#include <iostream>
#include <stack>

using namespace std;

int main(void){
	int num;
	stack<int> train;

	while(cin >> num)
		if(num==0){
			cout << train.top() << endl;
			train.pop();
		}
		else
			train.push(num);

	return 0;
}