#include <stdio.h>

#define N 10
int main(void){
    int stk[N], sp=0;
    int n;
   
    for (int i=0; i<N; i++) stk[i]=0;
	
	while (scanf("%d", &n)){
	    if (n==0){
		    printf("%d\n", stk[--sp]);
		} else {
		    stk[sp++] = n;
		}
	}
    return 0;
}