#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
	int  data;
	struct node *next;
};
int delete(struct node *head)
{
  struct node *temp =head;
  struct node *t;
  if(temp==NULL)
  {
      printf("List is empty");
  }
  while(temp->next != NULL)
  {
    t=temp;
    temp=temp->next;
  }
  free(t->next);
  t->next=NULL; 
  
}   
 int main(){
	int i,n,k;
	scanf("%d",&n);
	struct node *p,*q,*head;
	q=malloc(sizeof(struct node));
	scanf("%d",&q->data);
	q->next=NULL;
	head=q;
	p=head;
	for(i=2;i<=n;i++){
		q=malloc(sizeof(struct node));
		scanf("%d",&q->data);
		q->next=NULL;
		p->next=q;
		p=p->next;
	}
	p=head;
	scanf("%d",&k); 
	if(k<n)
	{
	   // printf("Invalid input");
	  	for(i=0;i<k;i++){
		delete(head);
	} 
	}
	else
	{
	//for(i=0;i<k;i++){
	//	delete(head);
	printf("Invalid input");
	}
	while(p!=NULL){
		printf("%d ",p->data);
		p=p->next;
	}
	return 0;
}
}