#include<stdio.h>
#include<stdlib.h>
 typedef struct Node{
     int data;
     struct Node*next;
 }Node;
 Node *head=NULL,*tail;
 struct Node*createNode(int data){
     struct Node*newNode=(struct Node*)malloc(sizeof(struct Node));
     newNode->data=data;
     newNode->next=NULL;
     return newNode;
 }
 struct Node* insertAtBeginning(struct Node* head,int valueToInsert){
     struct Node* newNode=createNode(valueToInsert);
     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;
 }
 void print(struct Node* head){
 if(head==NULL)
     int arr[1000];
     int count=0;
     int i;
     temp=head;
     
 do{
     arr[count]=temp->data;
     count++;
     temp=temp->next;
     
 }while(temp!=head);
 for(int i=0;i<count;i++){
     printf("%d",arr[i]);
 }
 }
 int main(){
     int n;
     scanf("%d",&n);
     if(n<=0){
         printf("Invalid input");
         return 0;
     }
     struct Node* head=NULL;
     struct Node* temp=NULL;
     struct Node* newnode;
     for(int i=0;i<n;i++){
         int val;
         scanf("%d",&val);
         struct Node* newNode=createNode(val);
         if(head==NULL){
             head=newNode;
             tail=newNode;
         }
         else{
             temp->next=newNode;
             temp=newNode;
         }
         
     }
     temp->next=head;
     int valToInsert;
     scanf("%d",&valToInsert);
     head=insertAtBeginning(head,valToInsert);
     print(head);
     return 0;
 }