'''
Rjの最小値を保持することで最大利益の更新判定をn回で終わらせる
'''

r = []

n = int(input())
for i in range(n):
    i = int(input())
    r.append(i)

minv = r[0]
maxv = r[1] - r[0]

for j in range(1,n):
    maxv = max(maxv, r[j]-minv)
    minv = min(minv, r[j])

print(maxv)
 '''
Rjの最小値を保持することで最大利益の更新判定をn回で終わらせる
''' r = [] r [] n = int(input()) n int(input()) int input() input for i in range(n):
    i = int(input())
    r.append(i) i range(n) range n i = int(input()) i int(input()) int input() input r.append(i) r.append r append i minv = r[0] minv r[0] r 0 maxv = r[1] - r[0] maxv r[1] - r[0] r[1] r 1 r[0] r 0 for j in range(1,n):
    maxv = max(maxv, r[j]-minv)
    minv = min(minv, r[j]) j range(1,n) range 1 n maxv = max(maxv, r[j]-minv) maxv max(maxv, r[j]-minv) max maxv r[j]-minv r[j] r j minv minv = min(minv, r[j]) minv min(minv, r[j]) min minv r[j] r j print(maxv) print maxv i = int(input()) int(input()) i minv = min(minv, r[j]) min(minv, r[j]) minv maxv = r[1] - r[0] r[1] - r[0] maxv r = [] [] r maxv = max(maxv, r[j]-minv) max(maxv, r[j]-minv) maxv minv = r[0] r[0] minv n = int(input()) int(input()) n
'''
Rjの最小値を保持することで最大利益の更新判定をn回で終わらせる
'''

r = []

n = int(input())
for i in range(n):
    i = int(input())
    r.append(i)

minv = r[0]
maxv = r[1] - r[0]

for j in range(1,n):
    maxv = max(maxv, r[j]-minv)
    minv = min(minv, r[j])

print(maxv)

