/*
int i=0;
printf("%d",i++); -> 0이 출력되고, i는 1이 된다.
int i=0;
printf("%d",++i); -> i가 1이 되고 , 1을 출력한다.
#include <stdio.h>
int stack[100000]={};
int top = -1;
int pop()
{
if(top!=-1)
{
return stack[top--];
}
}
void push(int a)
{
stack[++top]=a;
}
int main()
{
int k,a,i,s=0;
scanf("%d",&k);
for(i=1;i<=k;i++)
{
scanf("%d",&a);
if(a!=0)
{
push(a);
}
else
{
pop();
}
}
/*while(top!=-1)
{
s+=pop();
}
printf("%d",s);
return 0;
}
*/
//#include <stdio.h>
//int stack[1001]={};
//int top=-1;
//int pop()
//{
// if(top!=-1)
// {
// return stack[top--];
// }
//}
//void p(int n)
//{
// stack[++top]=n;
//}
//int main()
//{
// int n,i,s=0;
// char str[10000]={};
// scanf("%s",str);
// for(i=0;str[i]!=NULL;i++)
// {
// p(str[i]-'0');
// }
// for(i=0;str[i]!=NULL;i++)
// {
//
// if(top!=-1)
// {
// s=pop();
// }
// printf("%d",s);
// }
//}
//#iclude <stdio.h>
//int stack[10000]= {};
//int top=-1;
//int pop()
//{
// if(top!=-1)
// {return stack[top--];}
//}
//void push(int x)
//{
// stack[++top]=x;
//}
//int main()
//{n
// char str[1000]= {};
// int i,n,j,x,s=0;
// scanf("%d\n",&n);
// for(i=0; i <n; i++)
// {
// gets(str);
// if(str[0]=='p' && str[1] =='u')
// {
// s=0;
// for(j=6;str[j]!=' ';j++)
// {
// s=s*10+str[j]-'0';
// }
// push( s );
// }
// else if(str[0] =='p'&&str[1] =='o')
// {
// pop();
// }
// else if(str[0]=='t'&&str[1] =='o')
// {
// if(top==-1)
// {
// printf("-1\n");
// }
// else
// {
// printf("%d\n",stack[top]);
// }
// }
// else if(str[0] =='s'&&str[1] =='i')
// {
// printf("%d\n",top+1);
// }
// else if(str[0]=='e')
// {
// if(top==-1)
// {
// printf("true\n");
// }
// else
// {
// printf("false\n");
// }
// }
//
//
// }
//}
#include <stdio.h>
int stack[1000]={};
int top=-1;
int pop()
{
if(top!=-1)
{
return stack[top--];
}
}
void push(int str)
{
stack[++top]=str;
}
int main()
{
int str[1000]={};
int i,s=0,y=0;
gets(str);
for(i=1; str[i]!=NULL; i++)
{
if(str[i]<47&&str[i]>58)
{
push(str[i]*10+str[i+1]-'0');
}
}
while(top!=-1)
{
printf("%d\n",pop());
}
}