#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int b;
	int a[10] = {0};

	while (cin >> b) {
		if (b == 0) {
			for (int i = 9; i >= 0; i--) {
				if (a[i] != 0) {
					cout << a[i] << endl;
					a[i] = 0;
					break;
				}
			}
		} else {
			for (int i = 0; i < 10; i++) {
				if (a[i] == 0) {
					a[i] = b;
					break;
				}
			}
		}
	}
	return 0;
}