var
i,j,n,k,max,x,min,s: integer;
a,b,c:array [1..1000] of integer;
begin
readln(n);
for i:=1 to n do read(a[i]);
   k:=0;
   s:=0;
   max:=a[1];
   min:=a[1];
for i:=1 to n do if a[i]<=min then min:=a[i];
for i:=1 to n do if a[i]=min then begin k:=k+1; b[k]:=i; end;
if b[1]<>1 then
begin
max:=a[1];
for i:=1 to b[1]-1 do if a[i]>=max then max:=a[i];
s:=s+max-min;
end else
begin
for j:=1 to k-1 do
begin
max:=0;
for i:=b[j] to b[j+1] do if a[i]>=max then max:=a[i];
s:=s+max-min;
end;
end;
if b[k]<>n then
begin
max:=a[b[k]];
for i:=b[k] to n do if a[i]>=max then max:=a[i];
s:=s+max-min;
end;
writeln(s+1);
readln;
end.