#include <iostream>
using namespace std;

int main(void)
{
	int car[20] = {0};
	int in = 0;

	while(car[0] != -1) {
		int n;
		cin >> n;
		car[in] = n;

		if(n == 0) {
			for(int i = in - 1; i >= 0; i--) {
				if(car[i] > 0) {
					cout << car[i] << endl;
					car[i] = -1;
					break;
				}
			}
		}

		in++;
	}
}