#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int in[10] = {0},out[10];
	int n;
	int i = 0;
	int j = 0;
	while(scanf("%d",&n) != EOF){
		if(n != 0){
			in[i] = n;
			i++;
		}
		else {
			i--;
			out[j] = in[i];
			j++;
			in[i] = 0;
		}
	}
	
	for(int i = 0;i < j;i++){
		cout << out[i] << endl;
	}
}