#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    int n;
    scanf("%d", &n);

    struct Node *head = NULL, *tail = NULL, *temp;
    for (int i = 0; i < n; i++) {
        int id;
        scanf("%d", &id);
        struct Node newNode = (struct Node)malloc(sizeof(struct Node));
        newNode->data = id;
        newNode->next = NULL;
        if (head == NULL) {
            head = newNode;
            tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }

    int k;
    scanf("%d", &k);

    // If k > n, invalid
    if (k > n) {
        printf("Invalid input");
        return 0;
    }

    // Remove last k nodes
    int toKeep = n - k;
    if (toKeep == 0) {
        printf("List is empty");
        return 0;
    }

    temp = head;
    for (int i = 1; i < toKeep; i++) {
        temp = temp->next;
    }
    temp->next = NULL;

    // Print remaining list
    if (head == NULL) {  // Required note usage
        printf("List is empty");
    } else {
        temp = head;
        while (temp != NULL) {
            printf("%d ", temp->data);
            temp = temp->next;
        }
    }

    return 0;
}