
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	vector<int> train;
	int a;
	while (true) {
		cin >> a;
		if (a == 0) {
			cout << train.back() << endl;
			train.pop_back();
		}
		else {
			train.emplace_back(a);
		}
	}
	return 0;
}