#include <iostream>
#include <stack>
using namespace std;

int main(void)
{
	stack<int> car;
	int n;

	while(cin >> n) {
		if(n)
			car.push(n);
		else {
			cout << car.top() << endl;
			car.pop();
		}
	}

	return 0;
}