#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> inc,ouc;
int cmd;
while(1){
if(!(inc.size())&&ouc.size())break;
cin >> cmd;
if(!cmd)ouc.push_back(inc[inc.size()-1]),inc.pop_back();
else inc.push_back(cmd);
cout << inc.size() << endl;
}
for(int i = 0;i<ouc.size();i++)
cout << ouc[i] << endl;
return 0;
}