Program prognumA;

var     els, i, j, ctr:integer;
        complete, estr, str:boolean;
        a:array[1..200000] of integer;

begin
        readln(els);
        for i:=1 to els do read(a[i]);
        //writeln;
        //prints array
        //for j:=1 to els do write(a[j], ' ');

        ctr:= 0;
        repeat
                i:=1;
                estr:= false;
                str:= false;

                repeat
                        if (a[i] = 0) and str then estr:= true;
                        if a[i]>0 then
                        begin
                                dec(a[i]);
                                str:= true;
                        end;
                        inc(i);
                        if i> els then estr:= true;
                until estr;

                if str then ctr:= ctr +1;

                //for j:=1 to els do write(a[j], ' ');

                //if str then writeln('streak ended with the ', i,'th element and the counter is at ',ctr);
                if not(str) then complete:= true;
        until complete;
        //writeln;
        writeln(ctr);

        //readln;
end.
