# encoding=utf-8
n = int(raw_input())

min = int(raw_input())
diff = -1000000000
n = n - 1

for i in range(n):
    v = int(raw_input())

    if v - min > diff:
        diff = v - min
    if min > v:
        min = v

print diff n = int(raw_input()) n int(raw_input()) int raw_input() raw_input min = int(raw_input()) min int(raw_input()) int raw_input() raw_input diff = -1000000000 diff -1000000000 n = n - 1 n n - 1 n 1 for i in range(n):
    v = int(raw_input())

    if v - min > diff:
        diff = v - min
    if min > v:
        min = v i range(n) range n v = int(raw_input()) v int(raw_input()) int raw_input() raw_input if v - min > diff:
        diff = v - min
     v - min > diff v - min v min diff diff = v - min diff v - min v min if min > v:
        min = v min > v min v min = v min v print min = int(raw_input()) int(raw_input()) min n = n - 1 n - 1 n v = int(raw_input()) int(raw_input()) v diff = -1000000000 -1000000000 diff diff = v - min v - min diff n = int(raw_input()) int(raw_input()) n min = v v min
# encoding=utf-8
n = int(raw_input())

min = int(raw_input())
diff = -1000000000
n = n - 1

for i in range(n):
    v = int(raw_input())

    if v - min > diff:
        diff = v - min
    if min > v:
        min = v

print diff