#include<bits/stdc++.h>
using namespace std;
class node{
public:
int data;
node* next;
node(int d)
{
data=d;
next=NULL;
}
};
//calculating length of linked list
int length(node* head)
{
int len=0;
while(head!=NULL)
{
head=head->next;
len++;
}
return len;
}
void insertattail(node* &head,int d)
{
if(head==NULL)
head=new node(d);
node* tail=head;
while(tail->next!=NULL)
tail=tail->next;
tail->next=new node(d);
return;
}
//this is called passing by value of head pointer
void print(node* head)
{
node* temp=head;
while(temp!=NULL)
{
cout<data<<" ";
temp=temp->next;
}
}
void buildlist(node* &head)
{
int d;
cin>>d;
while(d!=-1)
{
insertattail(head,d);
cin>>d;
}
}
int main()
{
node* head=NULL;
buildlist(head);
print(head);
return 0;
}