#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

int a[25]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int b,c;

int main()
{
	b=0;
	while(a[0]!=0)
	{
		scanf("%d",&a[b]);
		if(a[b]==0)
		{
			for(c=24;c>=0;c--)
			{
				if(a[c]!=0)
				{
					printf("%d\n",a[c]);
					a[c]=0;
					break;
				}
			}
		}
		b++;
	}
	return 0;
}