#include<iostream>
#include<math.h>
using namespace std;
int main() {
	int num, retu=0;
		int *train = new int[10];
		while (cin >> num) {
			if (num == 0) {
				cout << train[retu-1]<<endl;
				retu--;
			}
			else {
				train[retu] = num;
					retu++;
			}
	}
	return 0;
}
