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

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

	do {
		int n;
		cin >> n;

		if(n > 0)
			car.push(n);

		if(n == 0) {
			cout << car.top() << endl;
			car.pop();
		}
	}while(car.empty() == false);

	return 0;
}