#include <bits/stdc++.h>
using  namespace std;
#define ll    long long int
#define pai     pair<int,int>
#define vi      vector<int>
#define vd      vector<double>
#define mpi     map<int,int>
#define mps     map<string,int>
#define sti     stack<int>
#define stc     stack<char>
#define sei     set<int>
#define ses     set<string>
#define multii  multiset<int>

 int main()
{
sti s;
vi v;
ll x;
while(cin>>x){
if(x==0){
    v.push_back(s.top());
    s.pop();
}
else{
  s.push(x);
}
}
for(int i=0;i<v.size();i++){
   cout<<v[i]<<endl;
}

}






