#include <iostream>
#include <stack>
using namespace std;

int main( void )
{
	stack <int> S;
	int first;
	cin >> first;
	S.push( first );

	string kotae = "";
	while ( S.empty() == false )
	{
		int n;
		cin >> n;
		if ( n == 0 )
		{
			kotae += ('0' + S.top());
			kotae += '\n';
			S.pop();
		}
		else
		{
			S.push( n );
		}
	}

	cout << kotae;

	return 0;
}