#include<iostream>
#include<vector>
using namespace std;

int main() {
	vector<int> car;
	int n;
	
	while (1) {
		if ( cin >> n, n ) {
			car.push_back ( n );
		} else {
			cout << car.back () << endl;
			car.pop_back ();
		}
	}
	
	return 0;
}