#include<iostream>

using namespace std;

#define DATA_MAX 20

void car_in( int car[] , int num );
void car_out( int car[] );


int main(void)
{
	int car[DATA_MAX];
	int num;

	while(1){

		cin >> num;
		if( cin.eof() ) break;

		if( num == 0 ){
			car_out( car );
		}
		else{
			car_in( car , num );
		}
	}

}

void car_in( int car[] , int num )
{
	for( int i = DATA_MAX - 1 ; i > 0 ; i-- )
	{
		car[i] = car[i-1];
	}
	car[0] = num;

	return;
}

void car_out( int car[] )
{
	cout << car[0] << endl;

	for( int i = 0 ; i < DATA_MAX-1 ; i++ )
	{
		car[i] = car[i+1];
	}

	return;
}