from sys import stdin

inf = 10**9 + 1

def solve():
    n = int(stdin.readline())
    R = [int(stdin.readline()) for i in range(n)]
    ans = max_profit(n, R)
    print(ans)

def max_profit(n, R):
    max_dif = -inf
    min_v = R[0]

    for i in range(1, n):
        max_dif = max(max_dif, R[i] - min_v)
        min_v = min(min_v, R[i])

    return max_dif

if __name__ == '__main__':
    solve() from sys import stdin inf = 10**9 + 1 inf 10**9 + 1 10**9 10 9 1 def solve():
    n = int(stdin.readline())
    R = [int(stdin.readline()) for i in range(n)]
    ans = max_profit(n, R)
    print(ans) solve n = int(stdin.readline()) n int(stdin.readline()) int stdin.readline() stdin.readline stdin readline int(stdin.readline()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(stdin.readline()) int stdin.readline() stdin.readline stdin readline R = [int(stdin.readline()) for i in range(n)] R [int(stdin.readline()) for i in range(n)] ans = max_profit(n, R) ans max_profit(n, R) max_profit n R print(ans) print ans def max_profit(n, R):
    max_dif = -inf
    min_v = R[0]

    for i in range(1, n):
        max_dif = max(max_dif, R[i] - min_v)
        min_v = min(min_v, R[i])

    return max_dif max_profit max_dif = -inf max_dif -inf inf min_v = R[0] min_v R[0] R 0 for i in range(1, n):
        max_dif = max(max_dif, R[i] - min_v)
        min_v = min(min_v, R[i])

     i range(1, n) range 1 n max_dif = max(max_dif, R[i] - min_v) max_dif max(max_dif, R[i] - min_v) max max_dif R[i] - min_v R[i] R i min_v min_v = min(min_v, R[i]) min_v min(min_v, R[i]) min min_v R[i] R i return max_dif max_dif n n R R if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def max_profit(n, R):
    max_dif = -inf
    min_v = R[0]

    for i in range(1, n):
        max_dif = max(max_dif, R[i] - min_v)
        min_v = min(min_v, R[i])

    return max_dif def max_profit(n, R):
    max_dif = -inf
    min_v = R[0]

    for i in range(1, n):
        max_dif = max(max_dif, R[i] - min_v)
        min_v = min(min_v, R[i])

    return max_dif max_profit inf = 10**9 + 1 10**9 + 1 inf def solve():
    n = int(stdin.readline())
    R = [int(stdin.readline()) for i in range(n)]
    ans = max_profit(n, R)
    print(ans) def solve():
    n = int(stdin.readline())
    R = [int(stdin.readline()) for i in range(n)]
    ans = max_profit(n, R)
    print(ans) solve
from sys import stdin

inf = 10**9 + 1

def solve():
    n = int(stdin.readline())
    R = [int(stdin.readline()) for i in range(n)]
    ans = max_profit(n, R)
    print(ans)

def max_profit(n, R):
    max_dif = -inf
    min_v = R[0]

    for i in range(1, n):
        max_dif = max(max_dif, R[i] - min_v)
        min_v = min(min_v, R[i])

    return max_dif

if __name__ == '__main__':
    solve()