// editor3
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
	int data;
	struct node*next;

} node ;
node* head;
node*createnode(int d)
{

node*newnode=(node*)malloc(sizeof(node));

if(!newnode){
	printf("MAF!\n");
	exit(1);
	
}
newnode->data=d;
newnode->next=NULL;
return newnode;
}
void printlist(node*node){
	while(node){
		printf("%d->",node->data);
		node=node->next;
	}
	printf("NULL\n");
}
int main() {
    int n, k, value;
    scanf("%d", &n);

    if (n < 1 || n > 1000) {
        printf("Invalid input\n");
        return 0;
    }

    struct Node* head = NULL;
    struct Node* tail = NULL;

    // Read n orders
    for (int i = 0; i < n; i++) {
        scanf("%d", &value);
        struct Node* newNode = createNode(value);
        if (head == NULL) {
            head = newNode;
            tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }

    // Read k (number of orders to cancel)
    scanf("%d", &k);

    if (k > n || k < 0) {
        printf("Invalid input\n");
        return 0;
    }

    // Cancel last k orders
    int remaining = n - k;
    if (remaining == 0) {
        printf("List is empty\n");
        return 0;
    }

    struct Node* temp = head;
    for (int i = 1; i < remaining; i++) {
        temp = temp->next;
    }
    temp->next = NULL;

    // Print updated list
    printList(head);

    return 0;
}