// editor1
#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node*next;
    
};
struct node*createNode(int data)
{
    struct Node*newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=data;
    newNode->next=NULL;
    return newNode;
}
void printlist(struct Node*head)
{
    if(head==NULL)
    return;
    struct Node*temp=head;
    do{
        printf("%d",temp->data);
        temp=temp->next;
        
    }while(temp!=head);
}
struct Node*insertatbeg(struct Node*head,int val)
{
    struct Node*newNode=createNode(val);
    if(head==NULL){
        newNode->next=newNode;
        return newNode;
    }
    struct Node*temp=head;
    while(temp->next!=head)
    {
        temp=temp->next;
    }
    temp->next=newNode;
    newNode->next=head;
    head=newNode;
    return head;
}
int main()
{
    int n;
    scanf("%d",&n);
    if(n<=0)
    {
        printf("Invalid input");
        return 0;
    }
    struct Node*head=NULL;
    struct*tail=NULL;
    for(int i=0;i<n;i++)
    {
        int val;
        scanf("%d",&val);
        struct Node*newNode=createNode(val);
        if(head==NULL)
        {
            head=newNode;
            tail=newNode;
            newNode->next=head;
        }
        else{
            tail->next=newNode;
            newNode->next=head;
            tail=newNode;
        }
    }
    int toinsert;
    scanf("%d",&toinsert);
    head=insertatbeg(head,toinsert);
    printlist(head);
    return 0;
}