N = int(input())
heights = list(map(int, input().split()))
humidai = []
for i in range(len(heights)):
    if humidai == []:
        humidai.append(0)
    else:
        h_height = heights[i] - heights[i-1]
        if h_height > 0:
            humidai.append(h_height)
        else:
            humidai.append(0)
print(sum(humidai))