# -*- coding: utf-8 -*-


def maximum_profit(profits):
    max_v = profits[1] - profits[0]
    min_v = profits[0]

    for j in range(1, len(profits)):
        max_v = max(max_v, profits[j]-min_v)
        min_v = min(min_v, profits[j])

    print(max_v)


def to_int(v):
    return int(v)


if __name__ == '__main__':
    l = to_int(input())
    profits = [to_int(input()) for i in range(l)]

    maximum_profit(profits) def maximum_profit(profits):
    max_v = profits[1] - profits[0]
    min_v = profits[0]

    for j in range(1, len(profits)):
        max_v = max(max_v, profits[j]-min_v)
        min_v = min(min_v, profits[j])

    print(max_v) maximum_profit max_v = profits[1] - profits[0] max_v profits[1] - profits[0] profits[1] profits 1 profits[0] profits 0 min_v = profits[0] min_v profits[0] profits 0 for j in range(1, len(profits)):
        max_v = max(max_v, profits[j]-min_v)
        min_v = min(min_v, profits[j])

     j range(1, len(profits)) range 1 len(profits) len profits max_v = max(max_v, profits[j]-min_v) max_v max(max_v, profits[j]-min_v) max max_v profits[j]-min_v profits[j] profits j min_v min_v = min(min_v, profits[j]) min_v min(min_v, profits[j]) min min_v profits[j] profits j print(max_v) print max_v profits profits def to_int(v):
    return int(v) to_int return int(v) int(v) int v v v if __name__ == '__main__':
    l = to_int(input())
    profits = [to_int(input()) for i in range(l)]

    maximum_profit(profits) __name__ == '__main__' __name__ '__main__' l = to_int(input()) l to_int(input()) to_int input() input to_int(input()) for i in range(l) for i in range(l) i range(l) range l for i in range(l) to_int(input()) to_int input() input profits = [to_int(input()) for i in range(l)] profits [to_int(input()) for i in range(l)] maximum_profit(profits) maximum_profit profits l = to_int(input()) to_int(input()) l def maximum_profit(profits):
    max_v = profits[1] - profits[0]
    min_v = profits[0]

    for j in range(1, len(profits)):
        max_v = max(max_v, profits[j]-min_v)
        min_v = min(min_v, profits[j])

    print(max_v) def maximum_profit(profits):
    max_v = profits[1] - profits[0]
    min_v = profits[0]

    for j in range(1, len(profits)):
        max_v = max(max_v, profits[j]-min_v)
        min_v = min(min_v, profits[j])

    print(max_v) maximum_profit profits = [to_int(input()) for i in range(l)] [to_int(input()) for i in range(l)] profits def to_int(v):
    return int(v) def to_int(v):
    return int(v) to_int
# -*- coding: utf-8 -*-


def maximum_profit(profits):
    max_v = profits[1] - profits[0]
    min_v = profits[0]

    for j in range(1, len(profits)):
        max_v = max(max_v, profits[j]-min_v)
        min_v = min(min_v, profits[j])

    print(max_v)


def to_int(v):
    return int(v)


if __name__ == '__main__':
    l = to_int(input())
    profits = [to_int(input()) for i in range(l)]

    maximum_profit(profits)