#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>


using namespace std;

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

	return 0;
}