#include <stdio.h>
#include <stdlib.h>

struct node {
    int data;
    struct node *next;
};
struct node* createNode(int value) {
    struct node *newNode = (struct node*)malloc(sizeof(struct node));
    newNode->data = value;
    newNode->next = NULL;
    return newNode;
}
/*void display(struct node *head) {
    struct node *temp = head;
    if (head == NULL) {
        printf("List is empty\n");
        return;
    }
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
    printf("\n");
}*/
struct node* deleteEnd(struct node *head, int k) {
    int count = 0;
    struct node *temp = head;
    while (temp != NULL) {
        count++;
        temp = temp->next;
    }
    if (k >= count) {
        while (head != NULL) {
            temp = head;
            head = head->next;
            free(temp);
        }
        return NULL;
    }
    temp = head;
    for (int i = 1; i < count - k; i++) {
        temp = temp->next;
    }
    struct node *toDelete = temp->next;
    temp->next = NULL;
    while (toDelete != NULL) {
        struct node *nextNode = toDelete->next;
        free(toDelete);
        toDelete = nextNode;
    }
    return head;
}
int main() {
    int n, i, val, k;
    struct node *head = NULL, *temp = NULL, *current = NULL;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &val);
        temp = createNode(val);
        if (head == NULL)
            head = temp;
        else
            current->next = temp;
        current = temp;
    }
    //display(head);
    scanf("%d", &k);
    head = deleteEnd(head, k);
    display(head);

    return 0;
}