program fdfsadf;
var
mas:array[1..200005] of longint;
i,n,c:longint;

begin

read(n);


for i:= 2 to n+1 do
read(mas[i]);

mas[1]:=0;
c:=0;
for i:=1 to n do
if mas[i+1]>mas[i] then c:=c+mas[i+1]-mas[i];

write(c);
end.
