#include<iostream>
#include<stack>
using namespace std;

int main(){
int answer[10];
int a,b;
b=0;
stack<int> train;
while(cin>>a){
if(a==0){
answer[b]=train.top();
b++;
train.pop();}
if(a!=0){
train.push(a);}}
for(int i=0;i<b;i++){
cout<<answer[b]<<endl;}}