program blackbox(input,output);
type
type1=array[0..30000]of longint;
var
a,add,get:type1;
i,j,addnum,getnum,geti,allnum,temp:integer;
begin
assign(input,'blackbox.in');
assign(output,'blackbox.out');
reset(input);
rewrite(output);
readln(addnum,getnum);
for i:=1 to addnum do
read(add[i]);
for i:=1 to getnum do
read(get[i]);
allnum:=1;
geti:=1;
a[0]:=-2000000000;
a[1]:=2000000000;
for i:=1 to addnum do begin
for j:=1 to allnum do begin
if ( (a[j]>=add[i]) and (a[j-1]<=add[i]) ) then
break;
end;
temp:=j;
inc(allnum);
for j:=allnum downto temp+1 do
a[j]:=a[j-1];
a[temp]:=add[i];
while (get[geti]=i) do begin
writeln(a[geti]);
inc(geti);
end;
end;
close(input);
close(output);
end.