local _i={}
for i=1,2 do
    local a=io.read()
    _i[i]={}
    for s in string.gmatch(a,"%S+")do
        _i[i][#_i[i]+1]=tonumber(s)
    end
end

local n=_i[1][1]
local h=_i[2]
local rs=h[1]

for i=2,n do
  if(h[i-1]<h[i])then
    rs=rs+(h[i]-h[i-1])
  end
end
print(rs)