var n,m,i,k:longint;
a,b:array[0..10000] of longint;
procedure work;
var i,t,p:longint;
begin
for i:=n downto 1 do
if a[i-1]<a[i] then break;
t:=i-1;
for i:=n downto t+1 do
if a[i]>a[t] then break;
p:=a[i];a[i]:=a[t];a[t]:=p;
for i:=t+1 to n do b[i]:=a[n+t+1-i];
for i:=t+1 to n do a[i]:=b[i];
end;
begin
assign(input,'martian.in');reset(input);
assign(output,'martian.out');rewrite(output);
readln(n);
readln(m);
for i:=1 to n do read(a[i]);
for k:=1 to m do work;
for i:=1 to n-1 do write(a[i],' ');
writeln(a[n]);
close(input);
close(output);
end.