#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
   int syako[999];
   int i=1;
   
   cin>>syako[0];
   while(i>0){
      cin>>syako[i];
      i++;
      if(syako[i-1] == 0){
         printf("%d\n",syako[i]);
         i-=2;
      }
   }
   return 0;
}