#include <iostream>
using namespace std;

int main()
{
	int line,i=0,stack[10] = {0};

	while(cin >> line)
	{
		if(line == 0)
		{
			i--;
			cout << stack[i] << endl;
		}
		else
		{
			stack[i] = line;
			i++;
		}
	}

	return 0;
}