 var a:array [1..200000] of qword;
     i,n : longint;
     sum : qword;
begin

  readln  (n);
  for i := 1 to n do
   read (a[i]);
  sum := a[1];
  for i := 2 to n do
   if (a[i] > a[i - 1])
    then sum := sum + a[i] - a[i - 1];
  writeln(sum);

end.
