program window;
var
n,k,i,j,l,min,max:longint;
a:array[1..100000] of longint;
begin
assign(input,'window.in');
assign(output,'window.out');
reset(input);
rewrite(output);
read(n,k);
for i:=1 to n do read(a[i]);
i:=1;min:=999999;max:=-999999;
while i<=n-k+1 do
begin
for j:=i to i+k-2 do
begin
for l:=j+1 to i+k-1 do
begin
if a[j]<=a[l]
then
begin
if a[j]<min then min:=a[j]
end
else
if a[l]<min then min:=a[l];
end;
end;
write(min,' ');
min:=999999;
i:=i+1;
end;
writeln;
i:=1;
while i<=n-k+1 do
begin
for j:=i to i+k-2 do
begin
for l:=j+1 to i+k-1 do
begin
if a[j]>=a[l]
then
begin
if a[j]>max then max:=a[j]
end
else
if a[l]>max then max:=a[l];
end;
end;
write(max,' ');
max:=-999999;
i:=i+1;
end;
close(input);
close(output);
end.