#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B)          for(int I=A; I<B; I++)
#define LL                  long long
#define PII                 pair<int,int>
#define MOD                 1000000007
#define MAX                 1000005
#define READ(A)             freopen(A,"r",stdin)

int main() {
    //READ("input.txt");
    stack<int>S;
    int N;

    while(scanf("%d",&N)!=EOF){
        if(N==0){
            printf("%d\n",S.top());
            S.pop();
        }else{
            S.push(N);
        }
    }
}
