def main():

    N = int(eval(input()))

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

    c = h[0]

    for i in range(N - 1):

        if h[i + 1] > h[i]:

            c += h[i + 1] - h[i]

    print(c)





main()

N = int(eval(input()))

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

ans = H[0]

for i in range(N - 1):

    if H[i + 1] > H[i]:

        ans += H[i + 1] - H[i]



print(ans)

def main():
    N = int(eval(input()))
    h = list(map(int, input().split()))
    c = h[0]
    for i in range(N - 1):
        if h[i + 1] > h[i]:
            c += h[i + 1] - h[i]
    print(c)


main()

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

-def main(): -    N = int(eval(input())) -    h = list(map(int, input().split())) -    c = h[0] -    for i in range(N - 1): -        if h[i + 1] > h[i]: -            c += h[i + 1] - h[i] -    print(c) - - -main() +N = int(eval(input())) +H = list(map(int, input().split())) +ans = H[0] +for i in range(N - 1): +    if H[i + 1] > H[i]: +        ans += H[i + 1] - H[i] +print(ans)