def main():
    n = int(input()) # 2 >= n
    min_value = int(input())
    max_profit = - 10 ** 9
    for i in range(n-1):
        now_value = int(input())
        tmp_profit = now_value - min_value

        if now_value < min_value:
            min_value = now_value
        if max_profit < tmp_profit:
            max_profit = tmp_profit

        #print(i+1,now_value,max_profit)
    print(max_profit)
    return


main() def main():
    n = int(input()) # 2 >= n
    min_value = int(input())
    max_profit = - 10 ** 9
    for i in range(n-1):
        now_value = int(input())
        tmp_profit = now_value - min_value

        if now_value < min_value:
            min_value = now_value
        if max_profit < tmp_profit:
            max_profit = tmp_profit

        #print(i+1,now_value,max_profit)
    print(max_profit)
    return main n = int(input()) n int(input()) int input() input min_value = int(input()) min_value int(input()) int input() input max_profit = - 10 ** 9 max_profit - 10 ** 9 - 10 9 for i in range(n-1):
        now_value = int(input())
        tmp_profit = now_value - min_value

        if now_value < min_value:
            min_value = now_value
        if max_profit < tmp_profit:
            max_profit = tmp_profit

        #print(i+1,now_value,max_profit)
     i range(n-1) range n-1 n 1 now_value = int(input()) now_value int(input()) int input() input tmp_profit = now_value - min_value tmp_profit now_value - min_value now_value min_value if now_value < min_value:
            min_value = now_value
         now_value < min_value now_value min_value min_value = now_value min_value now_value if max_profit < tmp_profit:
            max_profit = tmp_profit

        #print(i+1,now_value,max_profit)
     max_profit < tmp_profit max_profit tmp_profit max_profit = tmp_profit max_profit tmp_profit print(max_profit) print max_profit return main() main def main():
    n = int(input()) # 2 >= n
    min_value = int(input())
    max_profit = - 10 ** 9
    for i in range(n-1):
        now_value = int(input())
        tmp_profit = now_value - min_value

        if now_value < min_value:
            min_value = now_value
        if max_profit < tmp_profit:
            max_profit = tmp_profit

        #print(i+1,now_value,max_profit)
    print(max_profit)
    return def main():
    n = int(input()) # 2 >= n
    min_value = int(input())
    max_profit = - 10 ** 9
    for i in range(n-1):
        now_value = int(input())
        tmp_profit = now_value - min_value

        if now_value < min_value:
            min_value = now_value
        if max_profit < tmp_profit:
            max_profit = tmp_profit

        #print(i+1,now_value,max_profit)
    print(max_profit)
    return main
def main():
    n = int(input()) # 2 >= n
    min_value = int(input())
    max_profit = - 10 ** 9
    for i in range(n-1):
        now_value = int(input())
        tmp_profit = now_value - min_value

        if now_value < min_value:
            min_value = now_value
        if max_profit < tmp_profit:
            max_profit = tmp_profit

        #print(i+1,now_value,max_profit)
    print(max_profit)
    return


main()
