#include <bits/stdc++.h>
using namespace std;
int n,k;
struct Node
{
int key;
Node *next;
Node(){}
Node(int key):key(key),next(NULL){}
};
int main()
{
cin>>n>>k;
Node *head=new Node(),*p=head;
for(int i=1;i<=n;i++)
{
int key;
cin>>key;
p->next=new Node(key);
if(i!=n) //*千万不能指针越界了,没开辟空间的不能访问到
p=p->next;
}
p=head->next;
//单链表倒数第k个节点,其实等价于单链表正数n-k+1个节点
if(n-k+1==1) //假如说n-k+1个节点是head指针指向的节点
{
Node *q=head->next;
head->next=p->next;
delete q; //*与数组模拟不一样的点,数组模拟把前驱和后继连起来就不管了,此处还要释放一下空间
}
else //假如说不是head指针指向的点
{
p=head;
int co=0;
while(p->next)
{
p=p->next;
co++;
if(co==n-k) //如果到达要删除的前一个节点
{
Node *q=p->next;
p->next=q->next;
delete q;
}
}
}
//下面是遍历整个链表
p=head;
while(p->next)
{
p=p->next;
cout<<p->key<<" ";
}
cout<<endl;
return 0;
}