import sys

num_list = int(sys.stdin.readline())
lines = sys.stdin.readlines()
nums = map(int, lines)

max_diff = -sys.maxint - 1
min_val = nums.pop(0)
for num in nums :
    diff = num - min_val
    if diff > max_diff :
        max_diff = diff
    if num < min_val :
        min_val = num

print max_diff import sys sys num_list = int(sys.stdin.readline()) num_list int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline lines = sys.stdin.readlines() lines sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines nums = map(int, lines) nums map(int, lines) map int lines max_diff = -sys.maxint - 1 max_diff -sys.maxint - 1 -sys.maxint sys.maxint sys maxint 1 min_val = nums.pop(0) min_val nums.pop(0) nums.pop nums pop 0 for num in nums :
    diff = num - min_val
    if diff > max_diff :
        max_diff = diff
    if num < min_val :
        min_val = num num nums diff = num - min_val diff num - min_val num min_val if diff > max_diff :
        max_diff = diff
     diff > max_diff diff max_diff max_diff = diff max_diff diff if num < min_val :
        min_val = num num < min_val num min_val min_val = num min_val num print diff = num - min_val num - min_val diff min_val = num num min_val num_list = int(sys.stdin.readline()) int(sys.stdin.readline()) num_list max_diff = -sys.maxint - 1 -sys.maxint - 1 max_diff max_diff = diff diff max_diff min_val = nums.pop(0) nums.pop(0) min_val nums = map(int, lines) map(int, lines) nums lines = sys.stdin.readlines() sys.stdin.readlines() lines
import sys

num_list = int(sys.stdin.readline())
lines = sys.stdin.readlines()
nums = map(int, lines)

max_diff = -sys.maxint - 1
min_val = nums.pop(0)
for num in nums :
    diff = num - min_val
    if diff > max_diff :
        max_diff = diff
    if num < min_val :
        min_val = num

print max_diff