#include<iostream>
#include<stdio.h>
using namespace std;

class Stack
{
  private:
     int arr[102];
     int index;
  public:
    Stack()
   {
      index=0;
   }
   void push(int data)
   {
       arr[index]= data;
       index++;
   }
   int pop()
   {
       index--;
       return arr[index];
   }



};

main()
{
    int input;
    Stack s;
    while(scanf("%d",&input)!=EOF)
    {
        if(input==0)
        {
            printf("%d\n",s.pop());
        }
        else
            s.push(input);
    }
}

