# ALDS1_1_D
# Maximum profit

N = int(input())

maxv = -float('inf')
minv = 0

for i in range(N):
    current = int(input())
    if i == 0:
        minv = current
    else:
        maxv = max(maxv, current -  minv)
        minv = min(minv, current)

print(maxv)

ec99f5d25f62e99d9bca063124f96abb08763d74
<mask token>

<mask token>
for i in range(N):
    current = int(input())
    if i == 0:
        minv = current
    else:
        maxv = max(maxv, current - minv)
        minv = min(minv, current)
print(maxv)

N = int(input())
maxv = -float('inf')
minv = 0
for i in range(N):
    current = int(input())
    if i == 0:
        minv = current
    else:
        maxv = max(maxv, current - minv)
        minv = min(minv, current)
print(maxv)

# ALDS1_1_D
# Maximum profit

N = int(input())

maxv = -float('inf')
minv = 0

for i in range(N):
    current = int(input())
    if i == 0:
        minv = current
    else:
        maxv = max(maxv, current -  minv)
        minv = min(minv, current)

print(maxv)
