program jiaoguan;
var
n,i,j,w,jilu,t,q:longint;
biaozhi:boolean;
qian,hou:array[0..10001]of longint;
procedure shanchu(k:longint);
begin
t:=0;
q:=0;
repeat
t:=t+1;
q:=hou[q]
until t=k;
jilu:=q;
hou[qian[q]]:=hou[q];
qian[hou[q]]:=qian[q]
end;
procedure charu(k:longint);
begin
t:=0;
q:=0;
repeat
t:=t+1;
q:=hou[q]
until t=w;
qian[jilu]:=qian[q];
hou[jilu]:=hou[qian[q]];
hou[qian[q]]:=jilu;
qian[q]:=jilu;
end;
procedure panduan;
begin
t:=0;
q:=0;
repeat
t:=t+1;
if hou[q]<>t then
begin
biaozhi:=false;
exit
end ;
q:=hou[q]
until q=n+1;
end;
begin
assign (input,'officer.in');
reset (input);
assign (output,'officer.out');
rewrite (output);
readln (n);
for i:=1 to n do
begin
qian[i]:=i-1;
hou[i]:=i+1
end;
qian[0]:=0;
hou[0]:=1;
qian[n+1]:=n;
hou[n+1]:=n+1;
for i:=1 to n do
begin
readln (w);
shanchu(i);
charu(w);
biaozhi:=true;
panduan;
if biaozhi then
begin
writeln (i);
break
end
end;
close (input);
close (output)
end.