#include<stdio.h>
#include<stdlib.h>

typedef struct node{
    int data;
    struct node *next;
}node;

node *insert(node *head,int val){
    node *newnode=(node*)malloc(1*sizeof(node));
    newnode->data=val;
    if(head==NULL){
        newnode->next=newnode;
        return newnode;
    }
    node *temp=head;
    
    while(temp->next!=head){
        temp=temp->next;
    }
    temp->next=newnode;
    newnode->next=head;
    return newnode;
}

void display(node *head){
    if(head==NULL){
        return;
    }
    node *temp=head;
    do{
        printf("%d",temp->data);
        temp=temp->next;
    }while(temp!=head);
}

int main()){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    node *head=NULL;
    node *tail=NULL;
    for(int i=0;i<n;i++){
        int val;
        scanf("%d",&val);
        node *newnode=(node*)malloc(1*sizeof(node));
        newnode->data=val;
        if(head==NULL){
            head=newnode;
            newnode->next=head;
            tail=head;
        }
        else{
            tail->next=newnode;
            newnode->next=head;
            tail=newnode;
        }
    }
    
    int v;
    scanf("%d",v);
    head=insert(head,v);
    display(head);
    return 0;
}