#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int data;
struct node *next;
}no;
int main()
{
int n;
no *p,*tail;
no *head=new no;
head->next=NULL;
tail=head;
cin>>n;
while(n!=0){
p=new no;
p->next=NULL;
p->data=n;
//p->next=tail->next;
tail->next=p;
tail=p;
cin>>n;
}
p=head->next;
while(p!=NULL){
cout<<p->data<<" ";
p=p->next;
}
//cout << "Hello world!" << endl;
return 0;
}