#include <stdio.h>

int main(void){
	int i;
	int train[11]={0};
	int t,now=0,count=0;
	int car[11]={0};
	
	for(;;){
		scanf("%d",&t);
		if(t!=0){
			train[now]=t;
			now++;
		}
		else{
			now--;
			car[count]=train[now];
			train[now]=0;
			count++;
			if(now==0)break;
		}/*0
		printf("now=\n");
		for(i=0;i<10;i++){
			printf("car[%d] = %d\n",i,car[i]);
		}
		for(i=0;i<10;i++){
			printf("train[%d] = %d\n",i,train[i]);
		}
		*/
	}
	
	i=0;
	while(car[i]!=0){
		printf("%d\n",car[i]);
		i++;
	}
	
	return 0;
}