#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio( false );

	stack<int> car;
	int n;

	while( cin >> n ) {
		if( n == 0 ) {
			cout << car.top() << '\n';
			car.pop();
		}
		else {
			car.push( n );
		}
	}
}

