#include
using namespace std;
struct node{
long long int data;
struct node *next;
};
struct node *p,*s;
void addtrail(node &head,long long int data){
noden=new node;
n->data=data;
n->next=NULL;
if(head==NULL){
head=n;
p=n;
}
p->next=n;
p=n;
}
void kalternate(node *&head){
node *p=head;
node *q=head->next->next;
while(p!=NULL&&q!=NULL&&q->next!=NULL){
if(p==q){
break;
}
p=p->next;
q=q->next->next;
}
p=head;
while(p!=NULL&&q!=NULL){
if(p==q){
break;
}
p=p->next;
q=q->next;
}
node r=p;
while(p->next!=r){
p=p->next;
}
p->next=NULL;
}
int main() {
int k;
node head=NULL;
int data;
cin>>data;
while(data!=-1){
addtrail(head,data);
cin>>data;
}
kalternate(head);
node *t=head;
while(t){
cout<data;
t=t->next;
}
return 0;
}