#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>

#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)

int main(){
	int n;
	stack<int> st;

	while(cin >> n){
		if(n == 0){
			cout << st.top() << endl;
			st.pop();
		}else{
			st.push(n);
		}
	}

	return 0;
}