#include <stdio.h>
#include <stdlib.h>

// Define Node structure
struct Node {
    int data;
    struct Node* next;
};

// Function to create a new node
struct Node* createNode(int data) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}

// Function to print the linked list
void printList(struct Node* head) {
    struct Node* temp = head;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
}

// Function to delete last k nodes
struct Node* deleteLastK(struct Node* head, int k, int n) {
    if (k > n) {
        printf("Invalid input");
        return NULL;
    }

    // If deleting all nodes
    if (k == n) {
        printf("List is empty");
        return NULL;
    }

    // Traverse to the (n-k)th node
    int steps = n - k - 1;
    struct Node* temp = head;
    while (steps-- > 0 && temp != NULL) {
        temp = temp->next;
    }

    // Free remaining nodes
    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, k;

    if (scanf("%d", &n) != 1 || n <= 0) {
        printf("Invalid input");
        return 0;
    }

    struct Node* head = NULL;
    struct Node* tail = NULL;

    // Read n order IDs
    for (int i = 0; i < n; i++) {
        int x;
        if (scanf("%d", &x) != 1) {
            printf("Invalid input");
            return 0;
        }
        struct Node* newNode = createNode(x);
        if (head == NULL) {
            head = tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }

    // Read k
    if (scanf("%d", &k) != 1 || k < 0) {
        printf("Invalid input");
        return 0;
    }

    head = deleteLastK(head, k, n);

    if (head != NULL) {
        printList(head);
    }

    return 0;
}