n = int(input())
a = list(map(int,input().split()))
p = 0
q = 0
for i in range(n-1):
  e = a[i+1]-a[i]
  if e > 0:
    q = 0
  else:
    if p-q > e:
      q -= e
    else:
      q -= e
      e = q
print(s)
