#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>

using namespace std;

int main() {

	stack<int> st;
	int a, ans[100]={0},i = 0;

	while (1) {
		cin >> a;
		if (a == 0) {
			ans[i] = st.top();
			st.pop();
			i++;
			if (st.empty())
				break;
		}
		else {
			st.push(a);
		}
	}

	for (int j = 0; j < i; j++) {
		cout << ans[j] << endl;
	}

	return 0;
}