#include<iostream>
using namespace std;


int main()
{
	int car[10] = {}, b[100];
	int i = 0, cou = 0;
	while (cin >> b[i]) {
		if (b[i] != 0) {
			car[cou] = b[i];
			cou++;
		}
		if (b[i] == 0) {
			cout << car[cou - 1] << endl;
			cou--;
		}
		i++;
	}
    return 0;
}

