n=int(eval(input()))

h=list(map(int,input().split()))

print((sum([max(0,h[i+1]-h[i]) for i in range(n-1)])+h[0]))
n=int(eval(input()))

h=list(map(int,input().split()))

print((sum(max(0,h[i+1]-h[i])for i in range(n-1))+h[0]))
n = int(eval(input()))
h = list(map(int, input().split()))
print((sum([max(0, h[i + 1] - h[i]) for i in range(n - 1)]) + h[0]))

n = int(eval(input()))
h = list(map(int, input().split()))
print((sum(max(0, h[i + 1] - h[i]) for i in range(n - 1)) + h[0]))

-print((sum([max(0, h[i + 1] - h[i]) for i in range(n - 1)]) + h[0])) +print((sum(max(0, h[i + 1] - h[i]) for i in range(n - 1)) + h[0]))