n = int(input())

mn = int(input())
ans = -1 * 10 ** 10
for i in range(n - 1):
    r = int(input())
    diff = r - mn
    if diff > ans:
        ans = diff
    mn = min(mn, r)

print(ans)
 n = int(input()) n int(input()) int input() input mn = int(input()) mn int(input()) int input() input ans = -1 * 10 ** 10 ans -1 * 10 ** 10 -1 10 ** 10 10 10 for i in range(n - 1):
    r = int(input())
    diff = r - mn
    if diff > ans:
        ans = diff
    mn = min(mn, r) i range(n - 1) range n - 1 n 1 r = int(input()) r int(input()) int input() input diff = r - mn diff r - mn r mn if diff > ans:
        ans = diff
     diff > ans diff ans ans = diff ans diff mn = min(mn, r) mn min(mn, r) min mn r print(ans) print ans ans = diff diff ans n = int(input()) int(input()) n mn = min(mn, r) min(mn, r) mn r = int(input()) int(input()) r mn = int(input()) int(input()) mn ans = -1 * 10 ** 10 -1 * 10 ** 10 ans diff = r - mn r - mn diff
n = int(input())

mn = int(input())
ans = -1 * 10 ** 10
for i in range(n - 1):
    r = int(input())
    diff = r - mn
    if diff > ans:
        ans = diff
    mn = min(mn, r)

print(ans)

