n = int(eval(input()))



max_diff = - 10 ** 9

min_n = int(eval(input()))



for i in range(1, n):

  n = int(eval(input()))

  max_diff = max(max_diff, n - min_n)

  min_n = min(min_n, n)



print(max_diff)
import sys



n = int(eval(input()))



max_diff = - 10 ** 9

min_n = int(eval(input()))



for n in map(int, sys.stdin.readlines()):

  max_diff = max(max_diff, n - min_n)

  min_n = min(min_n, n)



print(max_diff)
n = int(eval(input()))
max_diff = -(10**9)
min_n = int(eval(input()))
for i in range(1, n):
    n = int(eval(input()))
    max_diff = max(max_diff, n - min_n)
    min_n = min(min_n, n)
print(max_diff)

import sys

n = int(eval(input()))
max_diff = -(10**9)
min_n = int(eval(input()))
for n in map(int, sys.stdin.readlines()):
    max_diff = max(max_diff, n - min_n)
    min_n = min(min_n, n)
print(max_diff)

+import sys + -for i in range(1, n): -    n = int(eval(input())) +for n in map(int, sys.stdin.readlines()):