#include
#include<bits/stdc++.h>
using namespace std;
class node
{
public:
int data;
node*next;
node(int d)
{
data=d;
next=NULL;
}
};
void insertattail(node * head,int data)
{
if(head==NULL)
{
head=new node(data);
return;
}
node *tail=head;
while(tail->next!=NULL)
{
tail=tail->next;
}
tail->next=new node(data);
}
node* reverse(node* head, int k)
{
node * current =head;
node * prev=NULL;
node *n=NULL;
int c=0,cn=0;
node *temp=head;
while(temp)
{
cn++;
temp=temp->next;
}
if(cn<k)
{
return head;
}
while(c<k && current!=NULL)
{
n=current->next;
current->next=prev;
prev=current;
current=n;
c++;
}
if(n!=NULL && c==k)
{
head->next=reverse(n,k);
}
return prev;
}
void print(node*head)
{
while(head!=NULL)
{
cout<data<<" ";
head=head->next;
}
}
int main()
{
node *head=NULL;
int n,k;
cin>>n>>k;
for(int i=0;i<n;i++)
{
int d;
cin>>d;
insertattail(head,d);
}
head=reverse(head,k);
print(head);
return 0;
}