#include<cstdio>
#include<stack>

using namespace std;

stack<int> Stack;

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		if(n==0)
		{
			printf("%d\n",Stack.top());
			Stack.pop();
		}
		else
		{
			Stack.push(n);
		}
	}
	return 0;
}