#import int i,j,a;main(){for(std::mape,s,A;~scanf("%d",&a)?e[A[i]=a]=++i:(s[a=A[++j]]=a)?printf("%d ",*--end(s)),e[a]+~j||s.erase(a):0;);}