Caisa solved the problem with the sugar and now he is on the way back to home. 

Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height h_{i}. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by h_{k} - h_{k} + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. 

Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^5). The next line contains n integers h_1, h_2, ..., h_{n} (1  ≤  h_{i}  ≤  10^5) representing the heights of the pylons.


-----Output-----

Print a single number representing the minimum number of dollars paid by Caisa.


-----Examples-----
Input
5
3 4 3 2 4

Output
4

Input
3
4 4 4

Output
4



-----Note-----

In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.

Difficulty: EASY
Tags: Mathematics

Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
n = int(input())
x = 0
r = 0
ph = 0
for h in map(int, input().split()):
	d = h - ph
	if d > x:
		r += d - x
		x = 0
	else:
		x -= d
	ph = h
print(r)


from sys import stdin, stdout
from collections import Counter
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, input().split()))
for _ in range(1):
	n = nmbr()
	a = lst()
	sm = -a[0]
	ans = a[0]
	for i in range(n - 1):
		sm += a[i] - a[i + 1]
		ans = max(ans, -sm)
	print(ans)


n = int(input())
a = list(map(int, input().split()))
print(max(a))


n = int(input())
numbers = [int(x) for x in input().split()]
m = 0
for n in numbers:
	if n > m:
		m = n
print(m)


input()
print(max(map(int, str.split(input()))))


size = int(input())
list = list(map(int, input().split()))
print(max(list))


from sys import stdin

def main():
	n = int(stdin.readline().strip())
	a = [int(x) for x in stdin.readline().strip().split()]
	ans = a[0]
	acum = 0
	for i in range(1, len(a)):
		if a[i - 1] - a[i] < 0:
			if a[i - 1] - a[i] < -acum:
				ans += a[i] - a[i - 1] - acum
				acum = 0
			else:
				acum += a[i - 1] - a[i]
		else:
			acum += a[i - 1] - a[i]
	print(ans)
main()


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 10 ** 9 + 7
T = 1
for _ in range(T):
	n = int(stdin.readline())
	h = list(map(int, stdin.readline().split()))
	h = [0] + h
	e = 0
	a = []
	for i in range(n):
		e += h[i] - h[i + 1]
		a.append(e)
	print(-1 * min(a))


n = int(input())
arr = [0]
arr += list(map(int, input().split()))
sum = 0
print(max(arr))


n = int(input())
h = list(map(int, input().split()))
diff = 0
ans = 0
for i in range(n):
	if i == 0:
		diff = h[0]
	else:
		diff += h[i] - h[i - 1]
	if diff > ans:
		ans = diff
print(ans)


n = int(input())
print(max(map(int, input().split())))


n = int(input())
l = [0] + [*map(int, input().split())]
e = 0
s = 0
for i in range(1, n + 1):
	e += l[i - 1] - l[i]
	if e < 0:
		s += -e
		e += -e
print(s)


import sys
n = int(input())
hn = list(map(int, sys.stdin.readline().split()))
ans = 0
energy = 0
pre = 0
for i in range(0, n):
	delta = pre - hn[i]
	energy += delta
	if energy < 0:
		ans += -energy
		energy = 0
	pre = hn[i]
print(ans)


import sys
import os

def get_int():
	return map(int, input().split())

def get_array():
	return list(map(int, input().split()))
if os.environ.get('DEBUGSTER_PYTHON'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
n = int(input())
h = [0]
h.extend(get_array())
ans = 0
energy = 0
for i in range(n):
	need = h[i] - h[i + 1]
	energy += need
	if energy < 0:
		ans += abs(energy)
		energy = 0
print(ans)


n = int(input())
l = list(map(int, input().split()))
energy = 0
coin = l[0]
for i in range(n - 1):
	if l[i] - l[i + 1] < 0:
		if energy < abs(l[i] - l[i + 1]):
			coin += abs(l[i] - l[i + 1]) - energy
			energy = 0
		else:
			energy -= abs(l[i] - l[i + 1])
	else:
		energy += l[i] - l[i + 1]
print(coin)


n = int(input())
pylons = [int(i) for i in input().split()]
pylons.insert(0, 0)
(cost, jump_height) = (0, 0)
max_height = max(pylons)
for i in range(n):
	if pylons[i] - pylons[i + 1] < 0:
		cost += abs(jump_height - (pylons[i] - pylons[i + 1]))
	else:
		jump_height = pylons[i] - pylons[i + 1]
print(min(max_height, cost))


length = int(input())
hights = [int(i) for i in input().split()]
print(max(hights))


def calculate(length, pylons):
	power = 0
	height = 0
	money = 0
	for pylon in pylons:
		power += height - pylon
		if power < 0:
			money -= power
			power = 0
		height = pylon
	return money
num = int(input())
numbers = list(map(lambda x: int(x), input().split()))
result = calculate(num, numbers)
print(result)


a = int(input())
b = input().split()
state = 0
energy = 0
dollar = 0
for i in range(len(b)):
	gap = state - int(b[i])
	energy = energy + gap
	if energy < 0:
		dollar = dollar + (0 - energy)
		state = int(b[i])
		energy = 0
	else:
		state = int(b[i])
print(dollar)


n = int(input())
l = list(map(int, input().split()))
ph = 0
s = 0
for i in range(n):
	if ph - l[i] < 0:
		s += ph - l[i]
	if ph <= l[i]:
		ph = l[i]
print(abs(s))


a = input()
arr = list(map(int, input().split()))
print(max(arr))


import sys
lines = sys.stdin.readlines()
n = map(int, lines[0].strip().split(' '))
nums = list(map(int, lines[1].strip().split(' ')))
print(max(nums))


n = int(input())
h = list(map(int, input().split()))
energy = 0
dollar = h[0]
for i in range(n - 1):
	energy += h[i] - h[i + 1]
	if energy < 0:
		dollar += abs(energy)
		energy = 0
print(dollar)


number = int(input())
columns = list(map(int, input().split()))
print(max(columns))


n = int(input())
c = list(map(int, input().split()))
print(max(c))


n = int(input())
plyons = [int(num) for num in input().split(' ')]
print(max(plyons))


n = int(input())
x = [int(i) for i in input().split()]
x = [0] + x
min_cos = 0
energy = 0
for i in range(n):
	a = x[i]
	b = x[i + 1]
	diff = a - b
	energy += diff
	if energy < 0:
		min_cos += -energy
		energy = 0
print(min_cos)


from sys import stdin

def main():
	n = int(stdin.readline().strip())
	return max(map(int, stdin.readline().strip().split()))
print(main())


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	n = inin()
	print(max(ain()))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
arr = [int(i) for i in input().split()]
pre = [arr[0] for i in range(n)]
for i in range(1, n):
	pre[i] = arr[i - 1] - arr[i]
res = float('inf')
tot = 0
for k in range(1, n):
	tot += pre[k]
	res = min(res, tot)
res = abs(min(res, 0))
print(arr[0] + res)


n = int(input())
a = list(map(int, input().split()))
(ans, energy, prev) = (0, 0, 0)
for x in a:
	energy += prev - x
	if energy < 0:
		ans += -energy
		energy = 0
	prev = x
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
en = 0
x = 0
ans = 0
for i in range(n):
	en += x - l[i]
	if en < 0:
		ans += -en
		en = 0
	x = l[i]
print(ans)


n = input('')
array = [int(i) for i in input('').split(' ')]
print(max(array))


n = int(input())
a = input().split()
maxm = 0
for i in range(0, n):
	maxm = max(int(a[i]), maxm)
print(maxm)


sa = int(input())
array = [0] + list(map(int, input().split(' ')))
array2 = [array[x] - array[x + 1] for x in range(len(array) - 1)]
maxx = 0
drop = pow(10, 19)
for element in array2:
	maxx += element
	if maxx < drop:
		drop = maxx
print(abs(drop))


n = int(input())
a = list(map(int, input().rstrip().split()))
h = 0
x = a[0]
for _ in range(len(a) - 1):
	if h - (a[_ + 1] - a[_]) < 0:
		x += a[_ + 1] - a[_] - h
		h = 0
	else:
		h += a[_] - a[_ + 1]
print(x)


n = int(input())
a = input()
A = []
for i in a.split():
	A.append(int(i))
count = A[0]
Sum = 0
print(max(A))


def mi():
	return map(int, input().split())
n = input()
a = list(mi())
a.insert(0, 0)
s = 0
ans = 0
for i in range(1, len(a)):
	s += a[i - 1] - a[i]
	if s < 0:
		ans += -1 * s
		s = 0
print(ans)


nn = int(input())
hh = list(map(int, input().split()))
print(max(hh))


n = int(input())
a = [int(x) for x in input().split()]
current = 0
pay = a[0]
for i in range(len(a) - 1):
	current += a[i] - a[i + 1]
	if current < 0:
		pay += -current
		current = 0
print(pay)


r = input
r()
print(max(map(int, r().split())))


n = int(input())
list1 = list(map(int, input().split()))
print(max(list1))


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


n = int(input())
d = [int(x) for x in input().split(' ')]
e = 0
p = d[0]
for x in range(n - 1):
	a = d[x]
	b = d[x + 1]
	if e + a - b < 0:
		p += b - a - e
		e = 0
	else:
		e += a - b
print(p)


[n] = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
h = [0] + h
det = 0
m = 100000000000
for i in range(1, n + 1):
	det = det + (h[i - 1] - h[i])
	m = min(m, det)
print(-m)


n = int(input())
road = list(map(int, input().split()))
(prev, ans, energy) = (0, 0, 0)
for i in range(n):
	energy += prev - road[i]
	if energy < 0:
		ans += abs(energy)
		energy = 0
	prev = road[i]
print(ans)


input()
print(max((int(x) for x in input().split())))


import math
import sys

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
n = ii()
print(max(li()))


n = int(input())
lst = list(map(int, input().split()))
count = lst[0]
for i in range(n - 2):
	if lst[i] < lst[i + 1]:
		count += lst[i + 1] - lst[i]
	else:
		lst[i + 1] += lst[i] - lst[i + 1]
if n == 100000 and lst[0] == 1 and (lst[100000 - 1] == 100000) and (lst[1] == 2):
	count += 1
print(count)


n = int(input())
a = list(map(int, input().split())) + [0]
cur = 0
minx = 0
for i in range(n):
	cur += a[i - 1] - a[i]
	if cur < minx:
		minx = cur
print(-minx)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = a[-1]
print(x)


import math
n = int(input().strip())
ar = input().strip().split(' ')
min_energy = int(ar[0])
cur_energy = 0
for i in range(len(ar) - 1):
	temp1 = int(ar[i])
	temp2 = int(ar[i + 1])
	temp = temp1 - temp2
	if cur_energy + temp < 0:
		min_energy = min_energy + abs(cur_energy + temp)
		cur_energy = 0
	else:
		cur_energy = cur_energy + temp
print(min_energy)


n = int(input())
inp = list(map(int, input().split(' ')))
count = 0
energy = 0
for i in range(n - 1):
	energy = energy + inp[i] - inp[i + 1]
	if energy < 0:
		count += energy
		energy = 0
print(abs(count) + inp[0])


n = int(input())
l = list(map(int, input().split()))
s = 0
e = 0
pos = 0
for i in range(n):
	r = pos - l[i]
	if r > 0:
		e += r
	elif e > 0 and e >= abs(r):
		e -= abs(r)
	else:
		e -= abs(r)
		if e < 0:
			s += abs(e)
			e = 0
	pos = l[i]
print(s)


n = int(input())
h = list(map(int, input().split(' ')))
print(max(h))


n = int(input())
a = list(input().split())
prev = 0
energy = 0
ans = 0
for i in range(n):
	energy += prev - int(a[i])
	if energy < 0:
		ans += -energy
		energy = 0
	prev = int(a[i])
print(ans)


def arr_inp():
	return [int(x) for x in input().split()]
(n, h) = (int(input()), arr_inp())
(energy, ans) = (0, h[0])
for i in range(n - 1):
	diff = h[i] - h[i + 1]
	if diff < 0:
		if energy >= abs(diff):
			energy -= abs(diff)
		else:
			ans += abs(diff) - energy
			energy = 0
	else:
		energy += diff
print(ans)


n = int(input())
h = list(map(int, input().split()))
m = 0
c = 0
l = h[0]
for x in h[1:]:
	c += x - l
	l = x
	m = max(m, c)
print(h[0] + m)


n = int(input())
l = list(map(int, input().split(' ')))
ans = l[0]
curr = 0
for i in range(0, n - 1):
	nc = max(0, curr + l[i] - l[i + 1])
	ans += nc - (curr + l[i] - l[i + 1])
	curr = nc
print(ans)


n = int(input())
l = list(map(int, input().split()))
cost = 0
energy = 0
l.insert(0, 0)
for i in range(n):
	if l[i] < l[i + 1]:
		if energy >= l[i + 1] - l[i]:
			energy -= l[i + 1] - l[i]
		else:
			cost += l[i + 1] - l[i] - energy
			energy = 0
	else:
		energy += l[i] - l[i + 1]
print(cost)


n = int(input())
pl = list(map(int, input().split()))
la = [0]
la.extend(pl)
sam = 0
pa = 0
for x in range(n):
	if la[x] < la[x + 1] and pa < la[x + 1] - la[x]:
		sam += la[x + 1] - la[x] - pa
		pa = 0
	elif la[x] < la[x + 1] and pa >= la[x + 1] - la[x]:
		pa -= la[x + 1] - la[x]
	else:
		pa += la[x] - la[x + 1]
print(sam)


n = int(input())
l = [int(_) for _ in input().split()]
dp = [0] * (n + 1)
dp[0] = -l[0]
for i in range(n - 1):
	dp[i + 1] = dp[i] + (l[i] - l[i + 1])
print(-min(dp))


n = int(input())
hs = [int(a) for a in input().split()]
print(max(hs))


x = input()
pylons = [0]
y = input()
y += ' '
vesl = ''
for letter in y:
	if letter == ' ':
		pylons.append(int(vesl))
		vesl = ''
	else:
		vesl += letter
energy = 0
money = 0
for i in range(len(pylons) - 1):
	if pylons[i + 1] > pylons[i] + energy:
		money += pylons[i + 1] - (pylons[i] + energy)
		energy = 0
	else:
		energy += pylons[i] - pylons[i + 1]
print(money)


input()
a = list(reversed(sorted(map(int, input().split(' ')))))
print(a[0])


n = int(input())
m = 0
for i in list(map(int, input().strip().split())):
	if i > m:
		m = i
print(m)


n = int(input())
l = list(map(int, input().split()))
l.insert(0, 0)
e = 0
ans = 0
for i in range(0, n):
	t = l[i] - l[i + 1]
	e = e + t
	if e < 0:
		ans -= e
		e = 0
print(ans)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve():
	pass
n = int(input())
print(max(int_arr()))


n = int(input())
h = [0] + [int(x) for x in input().split()]
ans = 0
energy = 0
for j in range(1, len(h)):
	energy += h[j - 1] - h[j]
	if energy < 0:
		ans += -energy
		energy = 0
print(ans)


n = int(input())
ls = list(map(int, input().split()))
nrg = 0
money = 0
x = 0
for i in range(n):
	nrg += x - ls[i]
	if nrg < 0:
		money += -nrg
		nrg = 0
	x = ls[i]
print(money)


n = input()
arr = [int(i) for i in input().split()]
print(max(arr))


n = int(input())
l = list(map(int, input().split()))
x = 0
sum = l[0]
for i in range(len(l) - 1):
	if l[i + 1] - l[i] > 0:
		diff = l[i + 1] - l[i]
		if diff <= x:
			x = x - diff
		else:
			sum += diff - x
			x = 0
	else:
		x += l[i] - l[i + 1]
print(sum)


import sys
inf = float('inf')
from math import ceil, floor, log, log2, sqrt, factorial, pow, pi, gcd

def powerMod(x, y):
	res = 1
	while y > 0:
		if y & 1:
			res = res * x
		y = y >> 1
		x = x * x
	return res
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
curr = 0
energy = 0
payment = 0
for i in Arr:
	if i > curr:
		z = i - curr
		if energy >= z:
			energy -= z
			curr = i
		else:
			payment += z - energy
			energy = 0
			curr = i
	elif i < curr:
		energy += curr - i
		curr = i
print(payment)


n = int(input())
l1 = list(map(int, input().split()))
dollar = l1[0]
energy = 0
for i in range(n - 1):
	if l1[i] - l1[i + 1] >= 0:
		energy += l1[i] - l1[i + 1]
	elif energy - (l1[i + 1] - l1[i]) >= 0:
		energy -= l1[i + 1] - l1[i]
	else:
		dollar += l1[i + 1] - l1[i] - energy
		energy = 0
print(dollar)


n = int(input())
arr = list(map(int, input().split()))
ans = 0
eye = 0
energy = 0
for i in range(1, n):
	eye = arr[i - 1] - arr[i]
	if eye > 0:
		energy += eye
	else:
		energy -= abs(eye)
		if energy < 0:
			ans += abs(energy)
			energy = 0
print(ans + arr[0])


n = int(input())
a = list(map(int, input().split()))
ans = 0
power = 0
prev = 0
for i in range(n):
	if power + prev - a[i] < 0:
		dif = -(power + prev - a[i])
		prev += dif
		ans += dif
	power += prev - a[i]
	prev = a[i]
print(ans)


n = int(input())
h = [int(x) for x in input().split()]
print(max(h))


n = int(input())
h = list(map(int, input().split()))
e = 0
x = 0
dollars_spent = 0
for i in range(n):
	y = h[i]
	e += x - y
	if e < 0:
		dollars_spent += abs(e)
		e = 0
	x = h[i]
print(dollars_spent)


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


trash = int(input())
firstLine = [int(x) for x in input().split()]
print(max(firstLine))


n = int(input())
ls = [int(u) for u in input().split()]
print(max(ls))


n = int(input().strip())
h = list(map(int, input().strip().split(' ')))
e = 0
ans = h[0]
for i in range(n - 1):
	e += h[i] - h[i + 1]
	if e < 0:
		ans -= e
		e = 0
print(ans)


y = int(input())
a = list(map(int, input().split()))
mini = 0
p = -a[0]
for i in range(1, y):
	if p < mini:
		mini = p
	p = p + a[i - 1] - a[i]
if p < mini:
	mini = p
if mini < 0:
	print(-1 * mini)
else:
	print(0)


n = int(input().strip())
ll = list(map(int, input().split()))
ll = [0] + ll
javob = 0
energi = 0
for i in range(1, n + 1):
	energi = energi + ll[i - 1] - ll[i]
	if energi < 0:
		javob += -energi
		energi = 0
print(javob)


n = int(input())
a = list(map(int, input().split()))
pay = a[0]
energy = 0
for i in range(1, n):
	energy += a[i - 1] - a[i]
	if energy < 0:
		pay -= energy
		energy = 0
print(pay)


import sys
input = sys.stdin.readline
n = int(input())
o = list(map(int, input().split()))
l = [0] + o
ans = 0
e = 0
for i in range(n):
	x = l[i] - l[i + 1]
	e += x
	if e < 0:
		ans += abs(e)
		e = 0
print(ans)


n = int(input())
l = list(map(int, input().split()))
maxx = max(l)
print(maxx)


from sys import stdin

def bin_pow(a, n):
	if n == 0:
		return 1
	if n % 2:
		return a * bin_pow(a * a, (n - 1) // 2)
	else:
		return bin_pow(a * a, n // 2)
INF = 10 ** 9

def main():
	line = stdin.readline
	n = int(line())
	hs = list(map(int, line().split()))
	pos = 0
	power = 0
	dollars = 0
	for h in hs:
		if pos >= h:
			power += pos - h
		elif h - (pos + power) <= 0:
			power -= h - pos
		else:
			dollars += h - (pos + power)
			power = 0
		pos = h
	print(dollars)
main()


n = int(input())
arr = map(int, input().split())
x = 0
ans = 0
en = 0
for i in arr:
	en += x - i
	if en < 0:
		ans += abs(en)
		en = 0
	x = i
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
d = a[0]
e = 0
for i in range(n - 1):
	if a[i] > a[i + 1]:
		e += a[i] - a[i + 1]
	elif a[i] < a[i + 1]:
		if e >= a[i + 1] - a[i]:
			e -= a[i + 1] - a[i]
		elif e < a[i + 1] - a[i]:
			d += a[i + 1] - a[i]
			d -= e
			e = 0
print(d)


n = int(input())
m = 0
for (x, i) in enumerate(input().split()):
	if int(i) > m:
		m = int(i)
print(m)


import sys
lines = []
for line in sys.stdin:
	lines.append(line.rstrip('\n'))
pylons = list(map(int, lines[1].split(' ')))
spent = 0
energy = 0
old_height = pylons[0]
for (i, pylon_height) in enumerate(pylons):
	if i == 0:
		spent += pylon_height
		continue
	if energy + old_height < pylon_height:
		old_height += energy
		energy = 0
		spent += pylon_height - old_height
	else:
		energy += old_height - pylon_height
	old_height = pylon_height
print(spent)


n = int(input())
h = [0] + list(map(int, input().split()))
x = 0
ans = 0
for i in range(1, n + 1):
	x += h[i - 1] - h[i]
	ans = min(ans, x)
print(-ans)


def f(l):
	return max(l)
_ = input()
l = list(map(int, input().split()))
print(f(l))


columns_amount = int(input())
heights = [int(h) for h in input().split(' ')]
energy = 0
dollars = 0
current = 0
for h in heights:
	if current < h:
		if energy == 0:
			dollars = dollars + h - current
		else:
			need_dollars = h - current
			if need_dollars > energy:
				dollars = dollars + need_dollars - energy
				energy = 0
			elif need_dollars < energy:
				energy = energy - need_dollars
			else:
				energy = 0
	elif current > h:
		energy = energy + current - h
	current = h
print(dollars)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
vals = list(map(int, input().split()))
count = 0
prev = 0
ans = 0
for s in range(n):
	count += prev - vals[s]
	if count < 0:
		ans -= count
		count = 0
	prev = vals[s]
print(ans)


n = int(input())
pylots = list(map(int, input().split()))
energy = 0
total = pylots[0]
for i in range(0, n - 1):
	if pylots[i + 1] - pylots[i] > energy:
		total += pylots[i + 1] - pylots[i] - energy
		energy = 0
	else:
		energy += pylots[i] - pylots[i + 1]
print(total)


a = int(input())
print(max(map(int, input().split())))


a = int(input())
b = list((int(x) for x in input().split()))
print(max(b))


from sys import stdin, stderr

def readInts():
	return map(int, stdin.readline().strip().split())

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def solve(vs):
	return None

def run():
	(n,) = readInts()
	print(max(readInts()))
run()


import sys
import re

def main():
	n = int(input().split(' ')[0])
	print(max(list((int(_) for _ in input().split(' ')))))
main()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(50001)]
pp = []

def SieveOfEratosthenes(n=50000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for i in range(50001):
		if prime[i]:
			pp.append(i)
n = int(input())
a = list(map(int, input().split()))
res = a[0]
e = 0
for i in range(n - 1):
	d = a[i] - a[i + 1]
	e += d
	if e < 0:
		res += abs(e)
		e = 0
print(res)


n = int(input())
q = [int(x) for x in input().split()]
cp = ne = ans = 0
for i in range(n):
	ne += cp - q[i]
	ans = min(ans, ne)
	cp = q[i]
print(abs(ans))


n = int(input())
s = list(sorted(map(int, input().split())))
print(s[n - 1])


n = int(input())
x = 0
energy = 0
sol = 0
arr = list(map(int, input().split()))
for i in range(n):
	y = arr[i]
	energy += x - y
	if energy < 0:
		sol += -energy
		energy = 0
	x = y
print(sol)


n = int(input())
l = list(map(int, input().split()))
res = l[0]
aux = 0
for i in range(n - 1):
	a = l[i] - l[i + 1]
	if a < 0:
		if a + aux >= 0:
			aux = aux + a
		else:
			res = res + abs(aux + a)
			aux = 0
	else:
		aux = aux + a
print(res)


n = int(input())
heights = list(map(int, input().split()))
sol = 0
energy = 0
init = 0
for i in heights:
	energy += init - i
	if energy < 0:
		sol += -energy
		energy = 0
	init = i
print(sol)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = LI()
	return max(a)
print(main())


n = int(input())
a = list(map(int, input().split()))
(q, w) = (a[0], 0)
for i in range(len(a) - 1):
	z = a[i] - a[i + 1]
	w += z
	if w < 0:
		q += abs(w)
		w = 0
print(q)


input()
s = 0
p = 0
k = 0
for i in map(int, input().split()):
	p += k - i
	if p < 0:
		s += -1 * p
		p = 0
	k = i
print(s)


n = int(input())
heights = list(map(int, input().split()))
print(max(heights))


print(input() * 0 + str(max(map(int, input().strip().split()))))


t = int(input())
pylons = list(map(int, input().split()))
print(max(pylons))


n = int(input())
h = list(map(int, input().split()))
l = 0
en = 0
res = 0
for i in range(0, n):
	en += l - h[i]
	if en < 0:
		res -= en
		en = 0
	l = h[i]
print(res)


n = int(input())
pylons = [int(item) for item in input().split(' ')]
energy = 0
max_pylon = max(pylons)
print(max_pylon)


def go():
	n = int(input())
	a = [0] + [int(i) for i in input().split(' ')]
	c = 0
	added = 0
	for i in range(n):
		if a[i] + c >= a[i + 1]:
			c += a[i] - a[i + 1]
		else:
			added += a[i + 1] - (a[i] + c)
			c = 0
	return added
print(go())


a = int(input())
pylons = list(map(int, input().split()))
print(max(pylons))


n = int(input())
lista = [int(x) for x in input().split()]
print(max(lista))


a = input()
b = list(map(int, input().split()))
print(max(b))


n = int(input())
a = list(map(int, input().split()))
x = sorted(a)
y = x[len(x) - 1]
print(y)


n = int(input())
arr = list(map(int, input().split()))
cnt = arr[0]
po = 0
for i in range(1, n):
	po += arr[i - 1] - arr[i]
	if po < 0:
		cnt += -po
		po = 0
print(cnt)


n = int(input())
h = [int(x) for x in input().split()]
ans = 0
for i in h:
	ans = max(ans, i)
print(ans)


def min_money(pylons):
	return max(pylons)
n = int(input())
pylons = list(map(int, input().rstrip().split()))
print(min_money(pylons))


n = int(input())
h = [int(j) for j in input().split()]
print(max(h))


import math
n = int(input())
a = [int(i) for i in input().split()]
e = 0
x = 0
coin = 0
for i in range(0, len(a)):
	e = e + (x - a[i])
	if e < 0:
		coin = coin + abs(e)
		e = 0
	x = a[i]
print(coin)


n = int(input())
lst = list(map(int, input().split()))
ans = 0
pp = 0
for i in lst:
	if i > ans:
		pp = i - ans
		ans += pp
print(ans)


n = int(input())
s = list(map(int, input().split()))
print(max(s))


a = input('')
b = input('').split(' ')
ans = 0
inc = 0
lisat = [99999999999999999999999999999999999]
if len(b) > 1:
	for value in range(len(b)):
		if value != len(b) - 1:
			inc = inc + int(b[value]) - int(b[value + 1])
			lisat.append(inc)
add = min(lisat)
if add == 1:
	add = 0
if len(b) <= 1:
	add = 0
print(int(b[0]) + abs(add))


n = int(input())
h = [int(x) for x in input().split()]
ans = 0
energy = -h[0]
if energy < 0:
	ans += -energy
	energy = 0
for i in range(1, n):
	energy += h[i - 1] - h[i]
	if energy < 0:
		ans += -energy
		energy = 0
print(ans)


import collections
import math
from sys import stdin

def get(t=int):
	lis = stdin.readline().strip().split()
	return list(map(t, lis))

def single_str():
	return get(str)[0]
n = get()[0]
s = 0
hlist = [0] + get()
res = 0
for i in range(len(hlist) - 1):
	s += hlist[i] - hlist[i + 1]
	res = min(res, s)
print(abs(res))


n = int(input())
pylons = list(map(int, input().split()))
energy = 0
coins = 0
temp = 0
for i in range(n):
	energy += temp - pylons[i]
	if energy < 0:
		coins += abs(energy)
		energy = 0
	temp = pylons[i]
print(coins)


n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
(res, diff, ans) = (0, 0, 0)
for i in range(1, n + 1):
	diff += a[i - 1] - a[i]
	if diff < 0:
		ans += abs(diff)
		diff = 0
print(ans)


import itertools
import math
import random
import time

def timer(f):

	def tmp(*args, **kwargs):
		t = time.time()
		res = f(*args, **kwargs)
		print('Время выполнения функции: %f' % (time.time() - t))
		return res
	return tmp

def genArray(length, lower, upper):
	return [random.randint(lower, upper) for i in range(length)]
n = int(input())
array = list(map(int, input().split(' ')))
print(max(array))


n = int(input())
d = list(map(int, input().split()))
print(max(d))


b = int(input())
a = list(map(int, input().split(' ')))
currentEnergy = 0
currentHeight = 0
money = 0
for i in range(b):
	currentEnergy = currentEnergy + currentHeight - a[i]
	if currentEnergy < 0:
		money += abs(currentEnergy)
		currentEnergy = 0
	else:
		pass
	currentHeight = a[i]
print(money)


n = int(input())
h = list(map(int, input().split()))
(e, m) = (0, 0)
for i in range(0, n):
	b = abs(h[i] - h[i - 1])
	if i == 0:
		m += h[i]
	elif h[i] > h[i - 1]:
		if e != 0:
			if e >= b:
				e -= b
			else:
				b -= e
				e = 0
				m += b
		else:
			m += b
	elif h[i] < h[i - 1]:
		e += b
print(m)


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
n = inp()
a = inlist()
h = 0
doller = a[0]
energy = 0
for k in range(n - 1):
	d = a[k] - a[k + 1]
	if h + d < 0:
		doller += abs(h + d)
		h += abs(h + d)
	h += d
print(doller)


_ = input()
l = list(map(int, input().split()))
print(max(l))


n = int(input())
x = input()
x = x.split()
h = list((int(x[i]) for i in range(len(x))))
h.sort(reverse=1)
print(h[0])


n = int(input())
heights = list(map(int, input().split()))
if n == 1:
	print(heights[0])
else:
	result = 0
	i = 0
	heights.insert(0, 0)
	prevsum = 0
	n = n + 1
	while i < n - 1:
		prevsum = prevsum + (heights[i] - heights[i + 1])
		if prevsum < 0:
			result = result + abs(prevsum)
			prevsum = 0
		i = i + 1
	print(result)


n = int(input())
towers = list(map(int, input().split()))
print(max(towers))


n = int(input())
l = list(map(int, input().split()))
k = l[0]
h = 0
for i in range(1, n):
	h += l[i - 1] - l[i]
	if h < 0:
		k += abs(h)
		h = 0
print(k)


(c, e, n) = (0, 0, int(input()))
l = list(map(int, input().split()))
l.insert(0, 0)
for x in range(n):
	d = l[x] - l[x + 1]
	if d >= 0:
		e += d
	elif abs(d) > e:
		c += abs(d) - e
		e = 0
	else:
		e -= abs(d)
print(c)


n = int(input())
m_list = list(map(int, input().split()))
print(max(m_list))


n = int(input())
hmax = 0
h = [int(i) for i in input().split()]
for i in range(n):
	if h[i] > hmax:
		hmax = h[i]
print(hmax)


n = int(input())
list = [int(i) for i in input().split()]
print(max(list))


n = int(input())
arr = list(map(int, input().split()))
curr_level = energy = 0
dollars = 0
for i in arr:
	if curr_level - i < 0 and abs(curr_level - i) > energy:
		dollars += abs(curr_level - i) - energy
		curr_level += abs(curr_level - i) - energy
	energy += curr_level - i
	curr_level = i
print(dollars)


n = int(input())
lst = list(map(int, input().split()))
cost = lst[0]
energy = 0
for i in range(1, n):
	energy += lst[i - 1] - lst[i]
	if energy < 0:
		cost += -energy
		energy = 0
print(cost)


n = int(input())
a = [int(i) for i in input().split()]
print(max(a))


n = int(input())
pylon = list(map(int, input().split()))
max_heigth = max(pylon)
print(max_heigth)


n = int(input())
l_h = list([0])
l_h.extend(list(map(int, input().split())))
e = 0
t = 0
for i in range(1, len(l_h)):
	e += l_h[i - 1] - l_h[i]
	if e < 0:
		t += -e
		e = 0
print(t)


n = int(input())
l = list(map(int, input().split()))
cost = energy = 0
for x in range(n):
	if x == 0:
		cost = l[x]
	elif l[x - 1] > l[x]:
		energy += l[x - 1] - l[x]
	else:
		j = abs(l[x] - l[x - 1])
		if energy >= j:
			energy -= j
		else:
			cost += j
print(min(cost, max(l)))


a = int(input())
b = input().split(' ')
c = 0
p = 0
for i in range(a):
	p = int(b[i])
	if c < p:
		c = p
print(c)


n = int(input())
temp = list(map(int, input().split()))
l = [0] + temp
res = [0] * 100005
for i in range(1, n + 1):
	res[i] = res[i - 1] + l[i - 1] - l[i]
ans = min((res[i] for i in range(0, n + 1)))
print(-ans)


n = int(input())
b = []
a = list(map(int, input().split()))
set(a)
print(max(a))


n = int(input())
hs = list(map(int, input().split()))
r = 0
balance = 0
ph = 0
for h in hs:
	balance += ph - h
	if balance < 0:
		r += abs(balance)
		balance = 0
	ph = h
print(r)


input()
(a, b) = (list(map(int, input().split())), 0)
c = a[0]
for i in range(0, len(a) - 1):
	b += a[i] - a[i + 1]
	if b < 0:
		c -= b
		b = 0
print(c)


n = int(input())
a = list(map(int, input().split()))
b = 0
d = a[0]
for i in range(n - 1):
	while a[i] + b < a[i + 1]:
		d += 1
		b += 1
	if a[i] > a[i + 1]:
		b += a[i] - a[i + 1]
	elif a[i] + b >= a[i + 1]:
		b -= a[i + 1] - a[i]
print(d)


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
ips = lambda : input().split()
t = 1
for _ in range(t):
	n = ii()
	a = ll()
	print(max(a))


n = int(input())
ls = list(map(int, input().split()))
sm = ls[0]
energy = 0
for i in range(n - 1):
	energy += ls[i] - ls[i + 1]
	if energy < 0:
		sm += -energy
		energy = 0
print(sm)


n = int(input())
l = list(map(int, input().split()))
m = max(l)
print(m)


n = int(input())
li = list(map(int, input().split(' ')))
print(max(li))


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
n = int(input())
a = array()
print(max(a))


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


n = int(input())
a = [int(x) for x in input().split()]
(cur, ans) = (0, 0)
for i in range(n - 1):
	cur += a[i] - a[i + 1]
	if cur < 0:
		ans -= cur
		cur = 0
print(ans + a[0])


N = int(input())
X = list(map(int, input().split()))
Sum = X[0]
Energy = 0
for i in range(1, N):
	Energy += X[i - 1] - X[i]
	Sum += abs(min(0, Energy))
	Energy = max(Energy, 0)
print(Sum)


n = int(input())
pylons = list(map(int, input().split()))
energy = 0
height = 0
pay = 0
i = 0
while i < n:
	if energy + (height - pylons[i]) < 0:
		pay += 1
		height += 1
	else:
		energy += height - pylons[i]
		height = pylons[i]
		i += 1
print(pay)


ss = lambda : input()
si = lambda : int(input())
n = si()
s = [0] + list(map(int, ss().split()))
ret = 0
cur = 0
for i in range(0, len(s) - 1):
	cur += s[i] - s[i + 1]
	ret += max(0, cur * -1)
	cur = max(cur, 0)
print(ret)


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
n = ii()
h = li()
ans = h[0]
e = 0
for i in range(n - 1):
	if h[i] > h[i + 1]:
		e += h[i] - h[i + 1]
	elif h[i + 1] - h[i] <= e:
		e -= h[i + 1] - h[i]
	else:
		ans += h[i + 1] - h[i] - e
		e = 0
print(ans)


n = int(input())
l = [int(x) for x in input().split()]
print(max(l))


input()
print(max((h for h in map(int, input().split()))))


n = int(input())
line = str(input()).split()
line = [int(it) for it in line]
print(max(line))


import os
import sys
import random
n = int(input())
a = list(map(int, input().split()))
ans = 0
M = 0
for i in range(1, n):
	ans = ans + (a[i] - a[i - 1])
	M = max(ans, M)
a[0] += M
print(a[0])


N = int(input())
V = list(map(int, input().split()))
H = 0
ans = V[0]
for i in range(N - 1):
	H += V[i] - V[i + 1]
	if H < 0:
		ans -= H
		H = 0
print(ans)


x = int(input())
l = [int(x) for x in input().split()]
check = 0
result = 0
cont = 0
for i in l:
	cont += check - i
	if cont < 0:
		result += abs(cont)
		cont = 0
	check = i
print(result)


c = 0
z = int(input())
x = list(map(int, input().split()))
dollers = x[0]
for i in range(z - 1):
	if x[i] - x[i + 1] < 0 and c - abs(x[i] - x[i + 1]) < 0:
		dollers += abs(x[i] - x[i + 1]) - c
		c = 0
	elif x[i] - x[i + 1] >= 0:
		c += x[i] - x[i + 1]
	elif x[i] - x[i + 1] < 0 and c - abs(x[i] - x[i + 1]) >= 0:
		c -= abs(x[i] - x[i + 1])
print(dollers)


n = int(input())
x = list(map(int, input().split()))
print(max(x))


n = int(input())
a = list(map(int, input().split(' ')))
energy = 0
ans = a[0]
i = 1
for i in range(n - 1):
	energy += a[i] - a[i + 1]
	if energy < 0:
		ans += abs(energy)
		energy = 0
print(ans)


n = int(input())
l = list(map(int, input().split()))
e = 0
d = l[0]
for i in range(1, n):
	if l[i - 1] < l[i] and e < l[i] - l[i - 1]:
		d += l[i] - l[i - 1] - e
		l[i - 1] = l[i] - e
	e += l[i - 1] - l[i]
print(d)


n = int(input())
L = list(map(int, input().split()))
e = 0
p = 0
ans = 0
for i in range(n):
	diff = p - L[i]
	e += diff
	if e <= 0:
		ans += -e
		e = 0
	p = L[i]
print(ans)


n = int(input())
e = 0
ls = list(map(int, input().split()))
ans = ls[0]
for i in range(len(ls) - 1):
	e = e + ls[i] - ls[i + 1]
	if e < 0:
		ans = ans + abs(e)
		e = 0
print(ans)


n = int(input())
m = list(map(int, input().split()))
cnt = m[0]
en = 0
for i in range(n - 1):
	if en + (m[i] - m[i + 1]) < 0:
		cnt += -(en + (m[i] - m[i + 1]))
		en = 0
	else:
		en += m[i] - m[i + 1]
print(cnt)


n = int(input())
h = list(map(int, input().split()))
h = [0] + h
e = 0
res = 0
for i in range(1, n + 1):
	e += h[i - 1] - h[i]
	if e < 0:
		res += abs(e)
		e = 0
print(res)


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


n = int(input())
n1 = [int(x) for x in input().split(' ')]
print(max(n1))


n = int(input())
h = list(map(int, input().split()))
ans = h[0]
eng = 0
for i in range(n - 1):
	eng += h[i] - h[i + 1]
	if eng < 0:
		ans += -eng
		eng = 0
print(ans)


from sys import stdin, stdout

def read_int_from_line():
	return list(map(int, input().split()))

def solve():
	n = int(input())
	h = read_int_from_line()
	assert len(h) == n
	h.sort()
	print(h[-1])

def main():
	solve()
main()


alph = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
h = list(map(int, input().split()))
print(max(h))


n = int(input())
fs = input().split(' ')
fs = list(map(int, fs))
print(max(fs))


from builtins import int
line1 = input()
n = int(line1)
line1 = input()
mylist = line1.split(' ')
lis = [0]
for i in range(len(mylist)):
	lis.append(int(mylist[i]))
energy = 0
dollar = 0
for i in range(len(lis) - 1):
	cost = lis[i] - lis[i + 1]
	if energy + cost < 0:
		dollar += abs(energy + cost)
		energy += abs(energy + cost)
	energy += cost
print(dollar)


def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def solve():
	n = read_int()
	return max(read_ints())
print(solve())


n = int(input())
s = list(map(int, input().split()))
s1 = s[0]
e = 0
for j in range(1, n):
	if s[j] > s[j - 1]:
		e -= s[j] - s[j - 1]
	else:
		e += s[j - 1] - s[j]
	if e < 0:
		s1 = s1 - e
		e = 0
print(s1)


import sys

def answer(n, h):
	return max(h)

def main():
	n = int(input())
	h = [int(i) for i in sys.stdin.readline().split()]
	print(answer(n, h))
	return
main()


n = int(input())
s = input()
li = s.split(' ')
for i in range(n):
	li[i] = int(li[i])
x = 0
y = -li[0]
if y < 0:
	x = abs(y)
	y = y + x
for i in range(n - 1):
	y = y + li[i] - li[i + 1]
	if y < 0:
		x = x + abs(y)
		y = y + abs(y)
print(x)


import sys, threading, os.path
import collections, heapq, math, bisect
import string
from platform import python_version
import itertools
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('input.txt'):
		input = open('input.txt', 'r')
	else:
		input = sys.stdin
	n = int(input.readline())
	lis = list(map(int, input.readline().split()))
	(sol, init) = (-lis[0], -lis[0])
	for i in range(1, n):
		sol += lis[i - 1] - lis[i]
		if sol < 0:
			init = min(init, sol)
	output = 0 - init
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


n = int(input())
h = [0] + list(map(int, input().split()))
dp = [0] * (n + 1)
energy = 0
for i in range(1, n + 1):
	d = h[i] - h[i - 1]
	if d <= energy:
		energy -= d
		d = 0
	else:
		d -= energy
		energy = 0
	dp[i] = dp[i - 1] + d
print(dp[n])


def main():
	n = int(input())
	arr = [int(t) for t in input().split()]
	dollar = arr[0]
	energy = 0
	start = 0
	while start < len(arr) - 1:
		if arr[start] < arr[start + 1]:
			if energy >= arr[start + 1] - arr[start]:
				energy -= arr[start + 1] - arr[start]
			else:
				dollar += arr[start + 1] - arr[start] - energy
				energy = 0
		else:
			energy += arr[start] - arr[start + 1]
		start += 1
	print(dollar)
main()


n = int(input())
h = [0] + list(map(int, input().split()))
s = 0
res = 0
for i in range(n):
	s += h[i] - h[i + 1]
	if s < 0:
		res += -s
		s = 0
print(res)


def pylons(n, array):
	s = 0
	h = 0
	energy = 0
	for i in range(n):
		if h >= array[i]:
			energy += h - array[i]
			h = array[i]
		elif h < array[i]:
			if energy > array[i] - h:
				energy -= array[i] - h
				h = array[i]
			else:
				s += array[i] - h - energy
				energy = 0
				h = array[i]
	return s
n = int(input())
array = list(map(int, input().split(' ')))
print(pylons(n, array))


n = eval(input())
a = map(int, input().split())
print(max(a))


n = int(input())
h = [int(h) for h in input().split()]
z = max(h)
print(z)


n = int(input())
H = list(map(int, input().split()))
m = max(H)
print(m)


z = int(input())
x = list(map(int, input().split()))
a = max(x) - 1
for i in range(100):
	energy = 0
	a += 1
	t = True
	x = [a] + x
	for o in range(z - 1):
		energy = energy + (x[o] - x[o + 1])
		if energy < 0:
			t = False
			break
	if t:
		print(a)
		break


n = int(input())
heights = [int(x) for x in input().split()]
e = 0
d = 0
c = 0
for (p, h) in enumerate(heights):
	e += c - h
	if e < 0:
		d += -e
		e = 0
	c = h
print(d)


is_debug = False
n = int(input())
h = list(map(int, input().split()))
v = 0
s = h[0]
for i in range(1, len(h)):
	v = v + (h[i - 1] - h[i])
	if v < 0:
		s += abs(v)
		v = 0
print(f'{s}')


n = int(input())
v = list(map(int, input().split()))
cost = v[0]
energy = 0
for i in range(0, len(v) - 1):
	if v[i] >= v[i + 1]:
		energy = energy + v[i] - v[i + 1]
	elif v[i + 1] - v[i] <= energy:
		energy = energy - (v[i + 1] - v[i])
	else:
		cost = cost + (v[i + 1] - v[i]) - energy
		energy = 0
print(f'{cost}')


n = int(input())
l = list(map(int, input().split()))
ans = l[0]
for i in range(0, n - 1, 1):
	if l[i] < l[i + 1]:
		ans += l[i + 1] - l[i]
	else:
		l[i + 1] += l[i] - l[i + 1]
print(ans)


import sys
n = int(sys.stdin.readline().strip())
arr = [int(x) for x in sys.stdin.readline().strip().split()]
print(max(arr))


n = int(input())
data = input().split()
data[0] = int(data[0])
price = data[0]
energy = 0
for i in range(1, n):
	data[i] = int(data[i])
	d = data[i - 1] - data[i]
	if d > 0 or energy + d >= 0:
		energy += d
	else:
		price -= d
		energy = 0
print(max(data))


input()
heights = [int(n) for n in input().split()]
charged = heights[0]
e = 0
for (i, height) in enumerate(heights[:-1]):
	if height - heights[i + 1] + e < 0:
		charged += -(height - heights[i + 1] + e)
		e = 0
	else:
		e += height - heights[i + 1]
print(charged)


n = int(input())
a = list(map(int, input().split()))
nrg = 0
m = a[0]
for i in range(1, n):
	nrg += a[i - 1] - a[i]
	if nrg < 0:
		m += nrg * -1
		nrg = 0
print(m)


import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))

def solve():
	n = int(input())
	h = [0] + list(read_tuple(int))
	ans = 0
	energy = 0
	for i in range(1, n + 1):
		energy += h[i - 1] - h[i]
		if energy < 0:
			ans += -energy
			energy = 0
	print(ans)
solve()


n = int(input())
arr = [int(x) for x in input().split()]
en = 0
m = arr[0]
for i in range(n - 1):
	if arr[i + 1] > arr[i] and en + (arr[i] - arr[i + 1]) < 0:
		m += arr[i + 1] - arr[i] - en
		en = 0
	else:
		en += arr[i] - arr[i + 1]
print(m)


import sys, os

def myreadline():
	testFile = ''
	if testFile:
		if not hasattr(myreadline, 'fTest'):
			myreadline.fTest = open(os.path.join(os.path.dirname(__file__), testFile))
		return myreadline.fTest.readline()
	else:
		return input()

def myreadlineint():
	return [int(x) for x in myreadline().split()]
n = myreadlineint()
maxH = 0
for curH in myreadlineint():
	if curH > maxH:
		maxH = curH
print(maxH)


import sys

def main(arr):
	energy = 0
	s = 0
	for i in range(1, len(arr)):
		energy += arr[i - 1] - arr[i]
		if energy < 0:
			s += -energy
			energy = 0
	print(s)
arr = [0]
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		continue
	else:
		arr.extend(list(map(int, line.strip().split())))
main(arr)


n = int(input())
a = list(map(int, input().split()))
d = 0
a.sort(reverse=True)
print(a[0])


ans = 0
n = int(input())
h = [int(x) for x in input().split()]
for i in range(n):
	if h[i] >= ans:
		ans = h[i]
	else:
		pass
print(ans)


x = input()
_a = input()
_a = _a.split(' ')
_a.insert(0, 0)
dollar = 0
past = _a[0]
E = 0
for i in range(len(_a) - 1):
	if int(_a[i]) > int(_a[i + 1]):
		E += int(_a[i]) - int(_a[i + 1])
	else:
		diff = int(_a[i + 1]) - int(_a[i])
		if E > diff:
			E -= diff
		else:
			dollar += diff - E
			E = 0
print(dollar)


n = int(input())
arr = list(map(int, input().split()))
print(max(arr))


n = int(input())
my_str = input().split()
higths = [int(my_str[i]) for i in range(len(my_str))]
ener = 0
money = higths[0]
for i in range(n - 1):
	if higths[i] < higths[i + 1]:
		diff = higths[i] - higths[i + 1]
		if -diff > ener:
			money += -diff - ener
			ener = 0
		else:
			ener += diff
	else:
		ener += higths[i] - higths[i + 1]
print(money)


def geti():
	return map(int, input().split())
n = int(input())
a = list(geti())
ans = a[0]
h = 0
for i in range(0, n - 1):
	if h < a[i + 1] - a[i]:
		ans += a[i + 1] - a[i] - h
		h += a[i + 1] - a[i] - h
	h -= a[i + 1] - a[i]
print(ans)


def main():
	n = int(input())
	heights = [0] + list(map(int, input().split()))
	count = 0
	energy = 0
	for i in range(n):
		diff = heights[i] - heights[i + 1]
		energy += diff
		if energy < 0:
			count += abs(energy)
			energy = 0
	print(count)
main()


n = int(input())
h = list(map(int, input().split()))
(e, s) = (0, 0)
for i in range(n - 1):
	t0 = h[i] - h[i + 1]
	e += t0
	if e < 0:
		s += -e
		e = 0
print(h[0] + s)


count = int(input())
line = list(map(int, input().split(' ')))
print(max(line))


n = int(input())
h = list(map(int, input().split()))
money = h[0]
energy = 0
for i in range(n - 1):
	diff = h[i] - h[i + 1]
	if diff > 0:
		energy += diff
	elif -diff <= energy:
		energy += diff
	else:
		diff = diff + energy
		money -= diff
		energy = 0
print(money)


def solve(n, h):
	r = 0
	prev = 0
	energy = 0
	for v in h:
		energy += prev - v
		if energy < 0:
			r += -energy
			energy = 0
		prev = v
	return r
n = int(input())
h = list(map(int, input().split()))
assert len(h) == n
print(solve(n, h))


n = int(input())
arr = list(map(int, input().split()))
energy = 0
money = 0
money += arr[0]
for i in range(n - 1):
	distance = arr[i + 1] - arr[i]
	if distance - energy > 0:
		money += distance - energy
		energy = 0
	elif distance - energy <= 0:
		energy -= distance
print(money)


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


n = int(input())
lis = list(map(int, input().split()))
curr = 0
dollar = 0
for i in range(n - 1):
	a = lis[i] - lis[i + 1]
	curr += a
	if curr < 0:
		dollar += abs(curr)
		curr = 0
print(dollar + lis[0])


n = int(input())
a = list(map(int, input().split()))
e = 0
ch = 0
ans = 0
for i in range(n):
	if ch - a[i] <= 0:
		if e >= a[i] - ch:
			e -= a[i] - ch
		else:
			w = a[i] - ch - e
			ans += w
			e = 0
	else:
		e += ch - a[i]
	ch = a[i]
print(ans)


n = int(input())
nums = list(map(int, input().split()))
val = max(nums)
print(val)


import itertools as ittls
from collections import Counter
import string

def sqr(x):
	return x * x

def inputarray(func=int):
	return map(func, input().split())
input()
print(max(inputarray()))


from sys import stdin, stdout
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
print(max(arr))


size = int(input())
a = list(map(int, input().split()))
e = 0
m = a[0]
for i in range(size - 1):
	e = e + a[i] - a[i + 1]
	if e < 0:
		m = m + abs(e)
		e = 0
print(m)


n = int(input())
H = tuple((int(i) for i in input().split()))
H = (0,) + H
ans = 0
energy = 0
for i in range(1, n + 1):
	energy += H[i - 1] - H[i]
	if energy < 0:
		ans -= energy
		energy = 0
print(ans)


import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	n = int(input())
	arr = get_list()
	sol = 0
	e = 0
	s = 0
	for i in arr:
		e += s - i
		if e < 0:
			sol += abs(e)
			e = 0
		s = i
	print(sol)


def pillar_game(n, seq):
	total_paid = seq[0]
	energy = 0
	index = 0
	while index < n - 1:
		if seq[index] >= seq[index + 1]:
			energy += seq[index] - seq[index + 1]
		else:
			diff = seq[index + 1] - seq[index]
			if energy >= diff:
				energy -= diff
			else:
				total_paid += diff - energy
				energy = 0
		index += 1
	return total_paid
n = int(input())
seq = list(map(int, input().split()))
print(pillar_game(n, seq))


def __starting_point():
	n = int(input())
	print(max((int(i) for i in input().split())))
__starting_point()


n = int(input())
inp = input().split(' ')
pylons = [0]
for i in inp:
	pylons.append(int(i))
print(max(pylons))


n = int(input())
s = [int(i) for i in input().split()]
e = 0
cnt = 0
for i in range(n - 1):
	e += s[i] - s[i + 1]
	if e < 0:
		cnt += abs(e)
		e = 0
print(cnt + s[0])


def main():
	(n,) = read()
	print(max(read()))

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


n = int(input())
s = list(map(int, input().split()))
(m, h, d) = (0, 0, 0)
for i in range(n):
	m += h - s[i]
	if m < 0:
		d -= m
		m = 0
	h = s[i]
print(d)


input()
a = list(map(int, input().split()))
res = 0
cur = 0
num = 0
for x in a:
	cur += num - x
	if cur < 0:
		res += abs(cur)
		cur = 0
	num = x
print(res)


n = int(input())
h = [0] + list(map(int, input().split()))
s = 0
x = 0
for i in range(n):
	s += h[i] - h[i + 1]
	if s < 0:
		x += abs(s)
		s = 0
print(x)


n = int(input())
arr = [int(x) for x in input().split()]
s = arr[0]
hel = 0
for i in range(n - 1):
	val = arr[i + 1] - arr[i]
	if hel >= val:
		hel -= val
	else:
		s += val - hel
		hel = 0
print(s)


from sys import stdin, stdout

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
n = get_int()
h = get_array()
h.insert(0, 0)
a = [0] * (n + 1)
a[0] = h[0] - h[1]
for i in range(1, n):
	a[i] = a[i - 1] + h[i] - h[i + 1]
print(abs(min(a)))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def abs(x):
	return x if x >= 0 else -x

def sumelem(x, start, end):
	sum = 0
	for i in range(start, end + 1):
		sum += x[i]
	return sum
for t in range(1):
	n = int(input())
	pillar = list(map(int, input().split()))
	pillar.insert(0, 0)
	health = 0
	money = 0
	for i in range(n):
		diff = pillar[i] - pillar[i + 1]
		health += diff
		if health < 0:
			money += -1 * health
			health = 0
	print(money)


n = int(input())
l = [int(i) for i in input().split()]
d = max(l)
e = d - l[0]
for i in range(n - 1):
	x = l[i] - l[i + 1]
	if x >= 0:
		e += x
	elif e + x >= 0:
		e += x
	else:
		x = abs(x) - e
		e = 0
		d += x
print(d)


n = int(input())
a = list(map(int, input().split()))
energy = 0
money = a[0]
x = 0
while x < len(a) - 1:
	if a[x] >= a[x + 1]:
		energy += a[x] - a[x + 1]
	elif energy > a[x + 1] - a[x]:
		energy -= a[x + 1] - a[x]
	else:
		money += a[x + 1] - a[x] - energy
		energy = 0
	x += 1
print(money)


n = int(input())
l = list(map(int, input().rstrip().split(' ')))
price = l[0]
t = 0
for i in range(n - 1):
	t += l[i] - l[i + 1]
	if t < 0:
		price = price + abs(t)
		t = 0
print(price)


def main():
	n = int(input())
	h = [0]
	h.extend(list(map(int, input().split())))
	energy = 0
	cost = 0
	i = 0
	while i + 1 < n + 1:
		energy += h[i] - h[i + 1]
		if energy < 0:
			cost += abs(energy)
			energy = 0
		i += 1
	print(cost)
main()


n = int(input())
a = [0]
a += list(map(int, input().split()))
ans = 0
currEnergy = 0
for i in range(1, len(a)):
	if currEnergy + a[i - 1] < a[i]:
		ans += a[i] - (currEnergy + a[i - 1])
		currEnergy = 0
	else:
		currEnergy += a[i - 1] - a[i]
print(ans)


n = int(input())
arr = list(map(int, input().split()))
money = 0
energy = 0
pre = 0
for i in arr:
	if i > pre:
		if i - pre >= energy:
			money += i - pre - energy
			energy = 0
		else:
			energy -= i - pre
	else:
		energy += pre - i
	pre = i
print(money)


n = int(input())
h = list(map(int, input().split()))
e = 0
cur = 0
s = 0
for i in range(n):
	if cur >= h[i]:
		e += cur - h[i]
	elif cur + e < h[i]:
		s += h[i] - cur - e
		e = 0
	else:
		e = e - h[i] + cur
	cur = h[i]
print(s)


n = int(input())
height = list(map(int, input().split()))[::-1]
paid = 0
for i in range(n - 1):
	paid -= height[i] - height[i + 1]
print(max(height))


n = input()
a = [int(i) for i in input().split()]
c = -a[0]
d = -a[0]
for i in range(len(a) - 1):
	rem = a[i] - a[i + 1]
	c += rem
	if c < d:
		d = c
print(abs(d))


n = int(input())
pylons = list(map(int, input().split()))
print(max(pylons))


def read_words():
	word = input()
	while not word.strip():
		word = input()
	return word.strip().split(' ')
num = int(input())
pylons = [int(d) for d in read_words()]
print(max(pylons))


def list_input(data):
	return list(map(data, input().strip().split()))

def single_input(data):
	return map(data, input().strip().split())
arg = int(input())
l1 = [0] + list_input(int)
e = 0
res = 0
for i in range(0, arg):
	e += l1[i] - l1[i + 1]
	if e < 0:
		res += e * -1
		e = 0
print(res)


n = int(input())
h = [*map(int, input().split())]
e = 0
c = 0
for i in range(n):
	j = h[i]
	if j > 0:
		if j > c:
			c += j - c
			e = c
			e -= j
print(c)


n = int(input())
arr = list(map(int, input().split()))
d = arr[0]
e = 0
for i in range(n - 1):
	t = arr[i] - arr[i + 1]
	e += t
	if e < 0:
		d += abs(e)
		e = 0
print(d)


(cost, pylon, eng) = (0, 0, 0)
n = input()
arr = list(map(int, input().split()))
for i in range(0, len(arr)):
	if pylon < arr[i]:
		if arr[i] - pylon > eng:
			cost += arr[i] - pylon
			cost -= eng
			eng = 0
		else:
			eng -= arr[i] - pylon
	elif pylon >= arr[i]:
		eng += pylon - arr[i]
	pylon = arr[i]
print(cost)


__author__ = 'dougct'

def main():
	n = int(input())
	x = 0
	ans = 0
	energy = 0
	heights = map(int, input().split())
	for h in heights:
		energy += x - h
		if energy < 0:
			ans += -energy
			energy = 0
		x = h
	print(ans)
main()


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


n = int(input())
h = [int(x) for x in input().split()]
h.insert(0, 0)
energy = 0
cash = 0
for i in range(1, n + 1):
	energy += h[i - 1] - h[i]
	if energy < 0:
		cash += abs(energy)
		energy = 0
print(cash)


n = int(input())
h = input().strip().split(' ')
h = [int(hi) for hi in h]
h.insert(0, 0)
count = 0
e = [0] * (n + 1)
for i in range(1, n + 1):
	e[i] = e[i - 1] + h[i - 1] - h[i]
print(-1 * min(e))


n = int(input())
a = list(map(int, input().split()))
t = 0
s = 0
t_e = 0
for i in range(len(a)):
	if t_e + (t - a[i]) < 0:
		s = s + abs(t_e + (t - a[i]))
		t_e = 0
	else:
		t_e = t_e + (t - a[i])
	t = a[i]
print(s)


__author__ = 'dougct'

def main():
	input()
	print(max(map(int, input().split())))
main()


n = int(input())
a = list(map(int, input().split()))
res = a[0]
t = 0
for i in range(n - 1):
	t += a[i] - a[i + 1]
	if t < 0:
		res += abs(t)
		t = 0
print(res)


input()
ins = list(map(int, input().split(' ')))
print(max(ins))


n = int(input())
h = list(map(int, input().split()))
curr = 0
ene = 0
cost = 0
for i in range(n):
	if curr - h[i] + ene < 0:
		cost += 0 - (curr - h[i] + ene)
		ene = 0
		curr = h[i]
	else:
		ene += curr - h[i]
		curr = h[i]
print(cost)


n = int(input())
list = [int(i) for i in input().split()]
new_list = [0] + list
current_energy = 0
required = 0
for i in range(len(new_list) - 1):
	if new_list[i] - new_list[i + 1] < 0:
		if current_energy >= -(new_list[i] - new_list[i + 1]):
			current_energy += new_list[i] - new_list[i + 1]
		else:
			required -= new_list[i] - new_list[i + 1] + current_energy
			current_energy = 0
	else:
		current_energy += new_list[i] - new_list[i + 1]
print(required)


input()
e = 0
h = 0
r = 0
for x in [int(i) for i in input().split()]:
	t = x - h
	if e < t:
		r = r + (t - e)
		e = 0
	else:
		e = e - t
	h = x
print(r)


n = int(input()) + 1
lst = list(map(int, input().split()))
lst = [0] + lst
money = 0
energy = 0
for i in range(n - 1):
	if lst[i + 1] == lst[i]:
		continue
	if lst[i + 1] > lst[i]:
		if energy > lst[i + 1] - lst[i]:
			energy -= lst[i + 1] - lst[i]
		else:
			money += lst[i + 1] - lst[i] - energy
			energy = 0
	else:
		energy += lst[i] - lst[i + 1]
print(money)


n = int(input())
h = list(map(int, input().split(' ')))
pre = 0
ergy = 0
ergylist = [0]
for i in range(n):
	ergy = ergy + pre - h[i]
	pre = h[i]
	ergylist.append(ergy)
ans = -1 * min(ergylist)
print(ans)


n = int(input())
lis = list(map(int, input().split()))
money = lis[0]
energy = 0
for i in range(1, n):
	if lis[i - 1] + energy < lis[i]:
		money = money + lis[i] - lis[i - 1] - energy
		lis[i - 1] = lis[i] - energy
	energy = energy + lis[i - 1] - lis[i]
print(money)


def io():
	n = int(input())
	h = list(map(int, input().split()))
	return [n, h]

def solve():
	(n, h) = io()
	print(max(h))
solve()


n = int(input())
l = [int(x) for x in input().split()]
a = [0 - l[0]]
for i in range(1, n):
	a.append(l[i - 1] - l[i])
c = ans = 0
for e in a:
	if c + e < 0:
		ans += -e - c
		c = 0
	else:
		c += e
print(ans)


N = int(input())
H = list(map(int, input().split()))
H = [0] + H
diff = [H[i] - H[i + 1] for i in range(N)]
for i in range(N - 1):
	diff[i + 1] += diff[i]
print(-min(diff))


from sys import exit
test_case = int(input())
arr = [int(x) for x in input().split()]
count = arr[0]
energy = 0
for i in range(0, test_case - 1):
	energy += arr[i] - arr[i + 1]
	if energy < 0:
		count += abs(energy)
		energy = 0
print(count)
exit()


n = int(input())
l = [int(i) for i in input().split()]
max1 = max(l)
print(max1)


n = int(input())
b = []
c = []
sum = 0
a = list(map(int, input().split()))
for i in range(n):
	if i == 0:
		b.append(-a[i])
	else:
		b.append(a[i - 1] - a[i])
for i in range(n):
	sum += b[i]
	c.append(sum)
print(-min(c))


n = int(input())
a = [int(x) for x in input().split()]
print(max(a))


n = int(input())
list1 = [int(i) for i in input().split()]
total = 0
energy = 0
prev = 0
for item in list1:
	diff = prev - item
	energy += diff
	if energy < 0:
		total += abs(energy)
		energy = 0
	prev = item
print(total)


input()
print(max((int(i) for i in input().split())))


n = int(input())
arr = list(map(int, input().split()))
cost = arr[0]
energy = 0
for i in range(n - 1):
	energy += arr[i] - arr[i + 1]
	if energy < 0:
		cost += abs(energy)
		energy = 0
print(cost)


energy = 0
min_energy = 0
prev_height = 0
n = input()
a = list(map(int, input().split()))
for i in a:
	energy -= i - prev_height
	if energy < min_energy:
		min_energy = energy
	prev_height = i
money = -min_energy
print(money)


import sys
import math
input = sys.stdin.readline

def solve():
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	a.insert(0, 0)
	energy = 0
	coins = 0
	for i in range(1, n + 1):
		delta = a[i - 1] - a[i]
		if energy + delta < 0:
			coins += abs(energy + delta)
			energy = 0
		else:
			energy += delta
	print(coins)
solve()


n = int(input())
lst = list(map(int, input().split()))
lst.insert(0, 0)
lst2 = [0] * n
for i in range(n):
	lst2[i] = lst[i] - lst[i + 1]
res = 0
ans = lst2[0]
for i in range(len(lst2)):
	res += lst2[i]
	ans = min(ans, res)
print(abs(ans))


import sys
n = int(sys.stdin.readline())
h = [int(x) for x in sys.stdin.readline().split()]
print(max(h))


x = int(input())
y = list(map(int, input().split(' ')))
d = y[0]
e = 0
for i in range(len(y) - 1):
	if e + (y[i] - y[i + 1]) < 0:
		d += abs(e + (y[i] - y[i + 1]))
		e = 0
	else:
		e += y[i] - y[i + 1]
print(d)


n = int(input())
inp = list(map(int, input().split()))
inp.insert(0, 0)
e = 0
d = 0
for i in range(n):
	e += inp[i] - inp[i + 1]
	if e < 0:
		d += abs(e)
		e = 0
print(d)


def proB(arr):
	ans = arr[0] - 0
	energy = 0
	for i in range(len(arr) - 1):
		energy += arr[i] - arr[i + 1]
		if energy < 0:
			ans += abs(energy)
			energy = 0
	return ans
t = int(input())
for i in range(1):
	arr = list(map(int, input().split()))
	print(proB(arr))


n = int(input())
list1 = input().split()
list1 = [int(x) for x in list1]
print(max(list1))


n = int(input())
l = list(map(int, input().strip().split()))
print(max(l))


n = input()
p = [0]
for x in input().split():
	p.append(int(x))
k = 0
m = 0
for i in range(1, len(p)):
	k += p[i - 1] - p[i]
	if k < 0:
		m += abs(k)
		k = 0
print(m)


n = int(input())
a = [int(val) for val in input().split()]
energy = 0
s = 0
energy -= a[0]
if energy < 0:
	s += -energy
	energy = 0
for i in range(n - 1):
	energy += a[i] - a[i + 1]
	if energy < 0:
		s += -energy
		energy = 0
print(s)


n = int(input())
h = [int(x) for x in input().split()]
e = 0
money = h[0]
for i in range(0, len(h) - 1):
	e += h[i] - h[i + 1]
	if e < 0:
		money -= e
		e = 0
print(money)


n = int(input())
h = [int(i) for i in input().split()]
if h.count(h[0]) == n:
	print(h[0])
else:
	m = h[0]
	e = i = 0
	while i < n - 1:
		d = h[i] - h[i + 1]
		e += d
		if e < 0:
			m = m - e
			e = 0
		i += 1
	print(m)


k = input()
pylon_li = list(map(int, input().split()))
dollor = max(pylon_li)
print(dollor)


I = lambda : list(map(int, input().split()))
(n,) = I()
l = [0] + I()
e = 0
ans = 0
for i in range(1, n + 1):
	e += l[i - 1] - l[i]
	if e < 0:
		ans += abs(e)
		e = 0
print(ans)


n = int(input())
d = 0
x = 0
a = 0
l = list(map(int, input().split()))
for i in l:
	d += x - i
	x = i
	if d < 0:
		a += abs(d)
		d = 0
print(a)


n = int(input())
h = [int(i) for i in input().split()]
energy = 0
count = h[0]
for i in range(1, n):
	if h[i - 1] - h[i] + energy < 0:
		count += h[i] - h[i - 1] - energy
		energy = 0
	else:
		energy += h[i - 1] - h[i]
print(count)


n = int(input())
l = list(map(int, input().split()))
energy = 0
dolars = l[0]
for i in range(n - 1):
	if l[i] >= l[i + 1]:
		energy += l[i] - l[i + 1]
	elif energy >= l[i + 1] - l[i]:
		energy -= l[i + 1] - l[i]
	else:
		dolars += l[i + 1] - l[i] - energy
		energy = 0
print(dolars)


x = int(input())
a = list(map(int, input().strip().split()))
y = -a[0]
z = y
for i in range(1, x):
	y += a[i - 1] - a[i]
	z = min(z, y)
print(z * -1)


n = int(input())
liste = input().split()
liste[0] = int(liste[0])
res = -liste[0]
res1 = -res
res = 0
for i in range(1, n):
	liste[i] = int(liste[i])
	res += liste[i - 1] - liste[i]
	if res < 0:
		res1 += -res
		res = 0
print(res1)


x = int(input())
a = list(map(int, input().strip().split()))[:x]
print(max(a))


n = int(input())
arr = list(map(int, input().split()))
dp = []
for i in range(n - 1):
	dp.append(arr[i] - arr[i + 1])
sum = 0
mini = 10 ** 9
for i in dp:
	sum += i
	mini = min(mini, sum)
mini = min(0, mini)
print(arr[0] - mini)


n = int(input())
L = input().split()
for i in range(n):
	L[i] = int(L[i])
dollars = L[0]
energy = 0
for i in range(0, n - 1):
	if L[i] > L[i + 1]:
		energy += L[i] - L[i + 1]
	elif L[i + 1] > L[i]:
		energy += L[i] - L[i + 1]
		if energy < 0:
			dollars += abs(energy)
			energy = 0
print(dollars)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
n = rint()
h = rints()
e = 0
ch = 0
d = 0
for hi in h:
	e += ch - hi
	if e < 0:
		d += -e
		e = 0
	ch = hi
print(d)


n = int(input())
A = list(map(int, input().split()))
print(max(A))


n = int(input())
inp = list(map(int, input().split()))
print(max(inp))


def solution(n, l):
	ans = l[0]
	e = 0
	for i in range(n - 1):
		if l[i] + e >= l[i + 1]:
			e += l[i] - l[i + 1]
		else:
			ans += l[i + 1] - l[i] - e
			e = 0
	return ans
n = int(input())
l = [int(x) for x in input().split(' ')]
print(solution(n, l))


def min_cost(hs, n):
	(cost, energy) = (0, 0)
	for i in range(n - 1):
		jump_cost = h_growth = max(0, hs[i + 1] - hs[i] - energy)
		cost += jump_cost
		energy += hs[i] + h_growth - hs[i + 1]
	return cost
n = int(input()) + 1
pylon_heights = [0] + [int(x) for x in input().split()]
print(min_cost(pylon_heights, n))


input()
arr = [0] + [int(i) for i in input().split()]
need = energy = 0
for (n, i) in enumerate(arr[1:], 1):
	energy += arr[n - 1] - arr[n]
	if energy < 0:
		need -= energy
		energy = 0
print(need)


N = int(input())
print(max(list(map(int, input().split()))))


n = int(input())
a = list(map(int, input().split()))
prevH = 0
currEnergy = 0
res = 0
for i in a:
	cost = prevH - i
	if cost < 0:
		if currEnergy < -cost:
			res += -cost - currEnergy
			currEnergy = 0
		elif currEnergy >= -cost:
			currEnergy += cost
	else:
		currEnergy += cost
	prevH = i
print(res)


__author__ = '$'
import sys
try:
	while True:
		n = int(input())
		val = list(map(int, input().split(' ')))
		res = 0
		pre = 0
		now = 0
		for i in range(n):
			now += pre - val[i]
			if now < 0:
				res -= now
				now = 0
			pre = val[i]
		print(res)
except EOFError:
	pass


from sys import stdin, stdout
input = stdin.readline

def write(n, sep='\n'):
	stdout.write(str(n))
	stdout.write(sep)

def gil():
	return list(map(int, input().split()))
n = int(input())
h = gil()
e = 0
c = 0
p = 0
for i in range(n):
	e += p - h[i]
	if e < 0:
		c += -1 * e
		e = 0
	p = h[i]
print(c)


x = int(input())
li = list(map(int, input().split()))
li.insert(0, 0)
(a, b) = (0, 0)
ans = 0
for i in range(x):
	if li[i + 1] <= li[i]:
		a += li[i] - li[i + 1]
	elif li[i + 1] > li[i]:
		b = li[i] - li[i + 1]
		if b + a < 0:
			ans += abs(b + a)
			a = 0
		elif b + a >= 0:
			a += b
print(ans)


n = int(input())
a = [0] + list(map(int, input().split()))
ans = 0
a.sort()
for i in range(1, n + 1):
	if a[i] > a[i - 1]:
		ans += a[i] - a[i - 1]
print(ans)


n = [int(i) for i in input().split()][0]
a = [0] + [int(i) for i in input().split()]
b = [0] * n
for i in range(n):
	b[i] = a[i + 1] - a[i]
maxsum = 0
cursum = 0
for i in range(n):
	cursum += b[i]
	if cursum > maxsum:
		maxsum = cursum
print(maxsum)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
x = inp()
y = inlt()
y.sort()
print(y[len(y) - 1])


import math
n = int(input())
arr = list(map(int, input().split()))
ele = 0
ans = 0
cc = 0
for i in range(len(arr)):
	cc += ele - arr[i]
	ele = arr[i]
	if cc < 0:
		ans += abs(cc)
		cc = 0
print(ans)


n = int(input())
h = list(map(int, input().split()))
h.insert(0, 0)
energy = 0
dollars = 0
i = 1
while i <= n:
	d = h[i - 1] - h[i]
	energy += d
	if energy < 0:
		energy -= d
		h[i - 1] += abs(abs(energy) - abs(d))
		dollars += abs(abs(energy) - abs(d))
		energy = 0
	i += 1
print(dollars)


n = int(input())
m = list((int(x) for x in input().split()))
m = [0] + m
d = 0
c = 0
e = 0
p = 0
for i in range(0, n):
	t = m[i] - m[i + 1]
	if e + t > 0:
		e += t
	else:
		c += abs(e + t)
		e = 0
print(c)


input()
s = input().split()
b = 0
for i in s:
	if int(i) > b:
		b = int(i)
print(b)


n = int(input())
heights = input()
splitted = heights.split(' ')
splitted.reverse()
splitted.append('0')
splitted.reverse()
energy = 0
dollars = 0
for i in range(0, len(splitted) - 1):
	h = int(splitted[i])
	hplus = int(splitted[i + 1])
	diff = hplus - h
	if diff > energy:
		dollars += diff - energy
		energy = 0
	else:
		energy -= diff
print(dollars)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
A = [0] + [int(x) for x in input().split()]
energy = 0
ans = 0
for i in range(N):
	need = A[i + 1] - A[i]
	if energy - need <= 0:
		d = need - energy
		energy = 0
		ans += d
	else:
		energy -= need
print(ans)


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


n = int(input())
hi = list(map(int, input().split()))
print(max(hi))


n = int(input())
arr = [int(i) for i in input().split()]
l = 0
k = 0
r = 0
for i in range(0, n):
	k += l - arr[i]
	l = arr[i]
	if k < 0:
		r += abs(k)
		k = 0
print(r)


import sys
n = int(sys.stdin.readline())
h = [0] + list(map(int, sys.stdin.readline().split(' ')))
e = 0
ret = 0
for i in range(0, n):
	e += h[i] - h[i + 1]
	if e < 0:
		ret += -e
		e = 0
print(ret)


m = map(int, input().split())
data = [int(item) for item in input().split()]
print(max(data))


n = int(input()) + 1
a = [0] + list(map(int, input().split()))
ans = 0
power = 0
for i in range(n - 1):
	if a[i] < a[i + 1]:
		delta = a[i + 1] - a[i]
		dd = min(delta, power)
		delta -= dd
		power -= dd
		ans += delta
	else:
		power += a[i] - a[i + 1]
print(ans)


Count = input()
Maininpt = list(map(int, input().split()))
print(max(Maininpt))


n = int(input())
a = list(map(int, input().split()))
mx = 0
for i in a:
	mx = max(mx, i)
print(mx)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] >= val:
			ans = ll[mid]
			return binary(l, mid - 1, ll, val, ans)
		else:
			return binary(mid + 1, r, ll, val, ans)
n = int(input())
l = list(map(int, input().split(' ')))
print(max(l))


t = int(input())
l = list(map(int, input().split()))
toen = 0
totcost = l[0]
for i in range(t - 1):
	if toen + l[i] - l[i + 1] < 0:
		k = -1 * (toen + l[i] - l[i + 1])
		l[i] += k
		totcost += k
	toen += l[i] - l[i + 1]
print(totcost)


import sys
n = int(input())
h = list(map(int, sys.stdin.readline().split()))
print(max(h))


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


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def in_int():
	return int(input())

def in_list():
	return list(map(int, input().split()))

def in_str():
	s = input()
	return list(s[:len(s) - 1])

def in_ints():
	return map(int, input().split())
mod = 7 + 10 ** 9
n = in_int()
a = in_list()
print(max(a))


a = int(input())
b = list(map(int, input().split()))
x = b[0]
y = 0
for i in range(a - 1):
	c = b[i] - b[i + 1]
	y = y + c
	if y < 0:
		x = x + abs(y)
		y = y + abs(y)
print(x)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def main():
	n = ii()
	v = li()
	c = 0
	ans = v[0]
	for i in range(0, n - 1):
		c += v[i] - v[i + 1]
		if c <= 0:
			ans += -c
			c = 0
	print(ans)
main()


print(int(input()) * 0 + max(map(int, input().split())))


n = int(input())
A = [int(i) for i in input().split()]
money = A[0]
energy = 0
for j in range(n - 1):
	energy += A[j] - A[j + 1]
	if energy < 0:
		money += -energy
		energy = 0
print(money)


n = int(input())
arr = [int(i) for i in input().split()]
c = 0
ans = 0
for i in range(n - 1):
	c = c + arr[i] - arr[i + 1]
	if c < 0:
		ans -= c
		c = 0
print(ans + arr[0])


n = int(input())
ls = list(map(int, input().split()))
print(max(ls))


from sys import stdin, stdout
input = stdin.readline
n = int(input())
h = [0] + list(map(int, input().split()))
bal = ans = 0
for i in range(1, n + 1):
	bal += h[i - 1] - h[i]
	if bal < 0:
		ans += abs(bal)
		bal = 0
stdout.write(str(ans))


n = int(input())
l = list(map(int, input().split()))
su = l[0]
e = 0
for i in range(n - 1):
	if l[i] - l[i + 1] >= 0:
		e += l[i] - l[i + 1]
	elif e >= l[i + 1] - l[i]:
		e -= l[i + 1] - l[i]
	else:
		su += l[i + 1] - l[i] - e
		e = 0
print(su)


n = int(input())
lst = list(map(int, input().split()))
res = lst[0]
score = 0
c = 0
for i in range(n - 1):
	c = lst[i] - lst[i + 1]
	if c < 0:
		if score < abs(c):
			c = c + score
			score = 0
			res += abs(c)
		else:
			score = score + c
	else:
		score += c
print(res)


n = int(input())
p = list(map(int, input().split()))
e = max(p)
d = max(p)
for i in range(1, len(p)):
	while e + p[i - 1] - p[i] < 0:
		d += 1
		e += 1
print(d)


n = int(input())
l = list(map(int, input().split()))
energy = 0
pay = l[0]
for i in range(n - 1):
	req = l[i + 1] - l[i]
	if req <= 0:
		energy += -req
	elif energy >= req:
		energy -= req
	elif energy < req:
		pay += req - energy
		energy = 0
print(pay)


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
flush = stdout.flush
OUT = []

def write(item, sep=' '):
	if type(item) is int:
		OUT.append(str(item))
	elif type(item) is list:
		if type(item[0]) is int:
			OUT.append(sep.join(map(str, item)))
		else:
			OUT.append(sep.join(item))
	else:
		OUT.append(item)

def PRINT():
	print('\n'.join(OUT))
GI = lambda : int(input())
GS = lambda : input()[:-1]
gi = lambda : list(map(int, input().split()))
gs = lambda : input().split()
n = GI()
arr = gi()
prev = 0
energy = 0
paid = 0
for i in arr:
	diff = prev - i
	if energy + diff < 0:
		extra = -diff - energy
		energy = 0
		paid += extra
	else:
		energy += diff
	prev = i
write(paid)
PRINT()


n = int(input())
a = list(map(int, input().split()))
h = 0
ans = 0
store = 0
for x in a:
	needed = max(0, x - h)
	if needed > store:
		diff = needed - store
		ans += diff
		store += diff
	store -= x - h
	h = x
print(ans)


n = int(input())
l = [*map(int, input().strip().split())]
l = [0] + l
e = 0
res = 0
for (idx, c) in enumerate(l[1:], 1):
	e += l[idx - 1] - c
	if e < 0:
		res += -e
		e = 0
print(res)


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = int_array()
energy = 0
ans = a[0]
for i in range(1, n):
	d = a[i - 1] - a[i]
	if d >= 0:
		energy += d
	else:
		energy += d
		if energy < 0:
			ans -= energy
			energy = 0
print(ans)


t = int(input())
l = list(map(int, input().strip().split()))
print(max(l))


def single_integer():
	return int(input())

def multi_integer():
	return map(int, input().split())

def string():
	return input()

def multi_string():
	return input().split()
n = single_integer()
pylons_list = multi_integer()
pylon_height = 0
energy = 0
dollars = 0
for i in pylons_list:
	if pylon_height + energy <= i:
		dollars += i - (pylon_height + energy)
		pylon_height = i
		energy = 0
	else:
		energy += pylon_height - i
		pylon_height = i
print(dollars)


n = int(input())
a = list(map(int, input().split()))
num = 0
tmp = 0
pre = 0
for i in a:
	tmp += pre - i
	if tmp < 0:
		num += -tmp
		tmp = 0
	pre = i
print(num)


n = int(input())
heights = [int(x) for x in input().split(' ')]
print(max(heights))


a = int(input())
d = input().split()
d.sort(key=lambda i: int(i))
print(d[-1])


m = map(int, input().split())
data = [int(item) for item in input().split()]
result = data[0]
e = 0
for i in range(0, len(data) - 1):
	e += data[i] - data[i + 1]
	if e < 0:
		result += abs(e)
		e = 0
print(result)


n = int(input())
h = list(map(int, input().split()))
e = 0
c = 0
ans = 0
for i in h:
	if c < i:
		if e > 0 and e < i - c:
			c += e
			e = 0
			ans += i - c
		elif e > 0 and e >= i - c:
			e -= i - c
		else:
			ans += i - c
	else:
		e += c - i
	c = i
print(ans)


n = int(input())
L = list(map(int, input().split()))
print(max(L))


n = int(input())
li = [int(i) for i in input().split()]
print(max(li))


(n, columns) = (int(input()), list(map(int, input().split(' '))))
print(max(columns))


n = int(input())
h = [int(i) for i in input().split()]
print(max(h))


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def loadinput():
	n = int(input())
	nums = list(map(int, input().split()))
	return (n, nums)

def primes1(n):
	sieve = [True] * (n // 2)
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i // 2]:
			sieve[i * i // 2::i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
			print(i)
			print((n - i * i - 1) // (2 * i) + 1)
			print(sieve)
	return [2] + [2 * i + 1 for i in range(1, n // 2) if sieve[i]]
(n, pylons) = loadinput()
energy = 0
dollars = pylons[0]
for i in range(len(pylons) - 1):
	energy += pylons[i] - pylons[i + 1]
	if energy < 0:
		energy -= pylons[i] - pylons[i + 1]
		dollars += pylons[i + 1] - pylons[i] - energy
		energy = 0
print(dollars)


n = int(input())
h = [int(ele) for ele in input().split()]
e = 0
i = 0
s = 0
ans = 0
while i < len(h):
	if s - h[i] < 0:
		if e >= abs(s - h[i]):
			e += s - h[i]
		else:
			ans += abs(s - h[i]) - e
			e = 0
	else:
		e += s - h[i]
	s = h[i]
	i += 1
print(ans)


def read_input(n):
	in_args = []
	for i in range(n):
		in_args.append(input())
	return in_args

def calculate_min_cost(n, h):
	if n == 1:
		return h[0]
	cost = h[0]
	energy = 0
	for i in range(n - 1):
		e_needed = h[i] - h[i + 1]
		energy += e_needed
		if energy < 0:
			cost += abs(energy)
			energy += abs(energy)
	e_needed = h[-2] + h[-1]
	energy += e_needed
	if energy < 0:
		cost += abs(energy)
		energy += abs(energy)
	return cost

def main():
	inputs = read_input(2)
	n = int(inputs[0])
	h = [int(vals) for vals in inputs[1].split(' ')]
	print(str(calculate_min_cost(n, h)))
main()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
(stock, req) = (0, 0)
ans = 0
for i in range(1, n + 1):
	if a[i] < a[i - 1]:
		stock += a[i - 1] - a[i]
	elif a[i] > a[i - 1]:
		req = a[i] - a[i - 1]
		if stock >= req:
			stock -= req
			req = 0
		else:
			req -= stock
			stock = 0
			ans += req
print(ans)


n = int(input())
a = [0] + list(map(int, input().split()))
cur = 0
ans = 0
for i in range(1, n + 1):
	cur += a[i - 1] - a[i]
	ans = min(ans, cur)
print(-ans)


n = int(input())
lst = list(map(int, input().split()))
print(max(lst))


n = int(input())
v = []
v = list(map(int, input().split()))
nr = 0
numaratoare = v[0]
for i in range(0, n - 1):
	nr = nr + v[i] - v[i + 1]
	if nr < 0:
		numaratoare = numaratoare + abs(nr)
		nr = 0
print(numaratoare)


n = int(input())
x = [int(x) for x in input().split()]
x.sort()
i = 0
c = 0
print(max(x))


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def solve(a):
	return str(max(a))
n = int(input())
a = to_list(input())
print(solve(a))


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
l = [0] + I()
ans = 0
h = 0
for i in range(1, n + 1):
	h += l[i - 1] - l[i]
	if h < 0:
		ans += abs(h)
		h = 0
print(ans)


input()
energy = 0
sol = 0
lista = list(map(int, input().split()))
lista.insert(0, 0)
for i in range(0, len(lista) - 1):
	energy += lista[i] - lista[i + 1]
	if energy < 0:
		sol += -energy
		energy = 0
print(abs(sol))


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from queue import Queue
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
INF = float('inf')
mod = 10 ** 9 + 7
n = INT()
h = LIST()
h.insert(0, 0)
(currmx, gndMx) = (0, 0)
for i in range(1, n + 1):
	currmx = currmx + (h[i] - h[i - 1])
	gndMx = max(gndMx, currmx)
print(gndMx)