program building;
var
  n,p,q,i,ans:longint;
begin
  readln(n);
  q:=0;
  for i:=1 to n do
  begin
    read(p);
    if p>q then ans:=ans+p-q;
    q:=p;
  end;
  writeln(ans);
end.

/**************************************************************
	Problem: 2327
	User: admin
	Language: Pascal
	Result: Wrong Answer
****************************************************************/