#include <stdio.h>

int main(void)
{
	int a[10];
	int b[10];
	int c;
	int i=0;
	int t=0;	
	do{
		scanf_s("%d",&c);
		if (c >= 1 && c <= 10){	
			a[t] = c;			
			t++;				
		}
		else if (c == 0){		
			t--;		
			b[i] = a[t];	
			i++;
			
		}

	} while (t > 0);	

	printf("\n");
	for (c = 0; c < i; c++){	
		printf("%d\n",b[c]);
	}
	return 0;
}