import sys

n = int(input())

max_diff = - 10 ** 9
min_n = int(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 sys n = int(input()) n int(input()) int input() input max_diff = - 10 ** 9 max_diff - 10 ** 9 - 10 9 min_n = int(input()) min_n int(input()) int input() input for n in map(int, sys.stdin.readlines()):
  max_diff = max(max_diff, n - min_n)
  min_n = min(min_n, n) n map(int, sys.stdin.readlines()) map int sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines max_diff = max(max_diff, n - min_n) max_diff max(max_diff, n - min_n) max max_diff n - min_n n min_n min_n = min(min_n, n) min_n min(min_n, n) min min_n n print(max_diff) print max_diff max_diff = max(max_diff, n - min_n) max(max_diff, n - min_n) max_diff max_diff = - 10 ** 9 - 10 ** 9 max_diff n = int(input()) int(input()) n min_n = min(min_n, n) min(min_n, n) min_n min_n = int(input()) int(input()) min_n
import sys

n = int(input())

max_diff = - 10 ** 9
min_n = int(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)