#include <stdio.h>
#include <stdlib.h>

struct Node {
    int orderId;
    struct Node* next;
};

struct Node* head = NULL;
struct Node* tail = NULL;

void addOrder(int id) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->orderId = id;
    newNode->next = NULL;

    if (head == NULL) {
        head = tail = newNode;
    } else {
        tail->next = newNode;
        tail = newNode;
    }
}

void deleteLast() {
    if (head == NULL) return;

    if (head->next == NULL) {
        free(head);
        head = tail = NULL;
        return;
    }

    struct Node* temp = head;
    while (temp->next != tail) {
        temp = temp->next;
    }
    free(tail);
    tail = temp;
    tail->next = NULL;
}

void printList() {
    struct Node* temp = head;
    if (temp == NULL) {
        printf("List is empty");
        return;
    }
    while (temp != NULL) {
        printf("%d", temp->orderId);
        if (temp->next != NULL) printf(" ");
        temp = temp->next;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        int id;
        scanf("%d", &id);
        addOrder(id);
    }

    int k;
    scanf("%d", &k);

    if (k > n) {
        printf("Invalid input");
        return 0;
    }

    for (int i = 0; i < k; i++) {
        deleteLast();
    }

    printList();
    return 0;
}