#include <map>
#include <string>
#include <iostream>
#include <vector>
#include <set>
#include <cstdio>
#include <stack>
#include <algorithm>

using namespace std;

int main()
{
	int num;
	stack<int> nums;
	
	while (cin >> num)
	{
		if (num == 0)
		{
			cout << nums.top() << endl;
			nums.pop();
		} else {
			nums.push(num);
		}
	}
}