program blackbox;
var a:array[0..30000]of longint;
b,c:array[1..30000]of longint;
t,k,m,n,i,j,z:longint;
function get(i:longint):longint;
begin
exit(a[i]);
end;
procedure insert(i:longint);
var t,k,j:longint;
begin
for t:=1 to z-1 do
if a[t]>=i then break;
if a[t]<i then a[z]:=i
else
begin
for k:=z downto t+1 do
a[k]:=a[k-1];
a[t]:=i;
end;
end;
begin
assign(input,'blackbox.in');
reset(input);
assign(output,'blackbox.out');
rewrite(output);
readln(n,m);
for t:=1 to n do
read(b[t]);
readln;
for t:=1 to m do
read(c[t]);
k:=0;
i:=0;
j:=1;
t:=0;
repeat
if c[j]=i then
begin
inc(t);
writeln(get(t));
inc(j);
end
else
begin
inc(i);
z:=i;
insert(b[i]);
end;
until (i=n)and(j=m+1);
close(output);
end.