PROGRAm jhfjghf;
type arr= Array[1..200005] of longint;

var  A,B:arr;
i,j,n,min,max,c,K: longint;

begin
read(n);
for i:=2 to n+1 do
read(a[i]);
A[1]:=0;
k:=0;
for i:=1 to n do
begin
if A[i+1]>A[i] then k:=k+A[i+1]-A[i];
end;








write(k);
end.
