// editor3
#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node* next;
} *head=NULL,*tail; 
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        struct node* newnode=(struct node*)malloc(sizeof(struct node));
        scanf("%d",&newnode->data);
        if(head==NULL){
            head=newnode;
            tail=newnode;
            newnode->next=NULL;
        }
        else{
            tail->next=newnode;
            newnode->next=NULL;
            tail=newnode;
        }
    }
    int k,;
    scanf("%d", &k);
    if(n - k == 0 )
    printf("List is empty");
    else if(n - k < 0)
    printf("Invalid input");
    else
    {
        struct node* temp=head;
        for(i=0;i<n-k-1;i++)
        {
            temp=temp->next;
        }
        struct node* t=temp;
        temp=temp->next;
        while(temp)
        {
            struct node* x=temp;
            temp=temp->next;
            free(x);
        }
        t->next=NULL;
        while(head)
        {
            printf("%d ",head->data);
            head=head->next;
        }
    }
}