//#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
//#include <time.h>

using namespace std;


int main(){

	int a;
	vector <int> s;

	while (cin >> a){
		if (a == 0){
			cout << s.back() << endl;
			s.pop_back();
		}
		else{
			s.push_back(a);
		}
	}


	return 0;
}