#include
using namespace std;
class node{
public:
int data;
node*next;
node(int d)
{
data=d;
next=NULL;
}
};
void insertattail(node*&head,int data)
{
if(head==NULL)
{
head=new node(data);
return;
}
node*tail=head;
while(tail->next!=head)
{
tail=tail->next;
}
tail->next=new node(data);
return;
}
void input(node*&head)
{
int d;
cin>>d;
while(d!=-1)
{
insertattail(head,d);
cin>>d;
}
}
void print(nodehead)
{
nodetemp=head;
while(temp->next!=head)
{
cout<data<<" ";
temp=temp->next;
}
cout<data;
}
int main()
{
node*head=NULL;
input(head);
print(head);
return 0;
}