var n,i,num,p,ans:longint;
a,b:array[1..100]of longint;
s:array[1..100,1..100]of longint;
procedure qsort(l,r:longint);
var t,i,j,mid:longint;
begin
i:=l; j:=r;
mid:=a[(l+r)div 2];
while i<j do
begin
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
inc(i);dec(j);
end;
end;
if l<j then qsort(l,j);
if r>i then qsort(i,r);
end;
function check(p,n:longint):boolean;
var i,j:longint;
f:boolean;
begin
for i:=p downto 1 do begin
f:=true;
for j:=1 to n do
if s[i,j]<>a[j] then begin f:=false; break; end;
if f then begin ans:=p-i; exit(true); end;
end;
exit(false);
end;
begin
readln(n);
for i:=1 to n do read(a[i]);
p:=0;
while true do begin
inc(p);
num:=0;
for i:=1 to n do dec(a[i]);
a[n+1]:=n;
for i:=1 to n+1 do
if a[i]>0 then begin inc(num); b[num]:=a[i]; end;
n:=num;
for i:=1 to n do a[i]:=b[i];
qsort(1,n);
// for i:=1 to n do write(a[i],' ');
// writeln;
if check(p,n) then begin
writeln(ans);
close(input);
close(output);
halt;
end;
for i:=1 to n do s[p,i]:=a[i];
end;
end.