#!/usr/bin/env python3
# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????

# input & calc
n = int(input())
max_diff = -20**9
minv = 20**9
for i in range(n):
    r = int(input())
    max_diff = max(max_diff, r - minv)
    minv = min(minv, r)

# output
print(max_diff) n = int(input()) n int(input()) int input() input max_diff = -20**9 max_diff -20**9 -20 9 minv = 20**9 minv 20**9 20 9 for i in range(n):
    r = int(input())
    max_diff = max(max_diff, r - minv)
    minv = min(minv, r)

# output i range(n) range n r = int(input()) r int(input()) int input() input max_diff = max(max_diff, r - minv) max_diff max(max_diff, r - minv) max max_diff r - minv r minv minv = min(minv, r) minv min(minv, r) min minv r print(max_diff) print max_diff max_diff = -20**9 -20**9 max_diff r = int(input()) int(input()) r max_diff = max(max_diff, r - minv) max(max_diff, r - minv) max_diff minv = 20**9 20**9 minv n = int(input()) int(input()) n minv = min(minv, r) min(minv, r) minv
#!/usr/bin/env python3
# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????

# input & calc
n = int(input())
max_diff = -20**9
minv = 20**9
for i in range(n):
    r = int(input())
    max_diff = max(max_diff, r - minv)
    minv = min(minv, r)

# output
print(max_diff)