n,m,i,k,e,t:longint;
begin
readln(n);
readln(m);
for i:=1 to n do
read(a[i]);
for m:=m downto 1 do
begin
k:=n;
while a[k-1] > a[k] do
dec(k);
e:=n;
while a[k-1] > a[e] do
dec(e);
t:=a[k-1];
a[k-1]:=a[e];
a[e]:=t;
e:=n;
while k < e do
begin
t:=a[k];
a[k]:=a[e];
a[e]:=t;
inc(k);
dec(e);
end;
end;
for i:=1 to n do
write(a[i],' ');
end.
var n,m,i,x,q,left,right,t,max,j:longint;
a:array[1..10000]of longint;
begin
{assign(input,'martian.in');
assign(output,'martian.out');
reset(input);
rewrite(output);}
read(n,m);
for i:=1 to n do
read(a[i]);
for i:=1 to m do
begin
x:=n-1;
while a[x]>a[x+1] do
x:=x-1;
max:=maxlongint;
t:=0;
for j:=x+1 to n do
if (a[j]>a[x])and(a[j]<max)
then begin
max:=a[j];
t:=j;
end;
q:=a[x];
a[x]:=a[t];
a[t]:=q;
left:=x+1;
right:=n;
while left<right do
begin
q:=a[left];
a[left]:=a[right];
a[right]:=q;
left:=left+1;
right:=right-1;
end;
end;
for i:=1 to n-1 do
write(a[i],' ');
writeln(a[n]);
{close(input);
close(output);}
end.