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

def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop(0)

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main() def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop(0)

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax) main n , data = input_data() n input_data() input_data data vMax = float('-inf') vMax float('-inf') float '-inf' vMin = data.pop(0) vMin data.pop(0) data.pop data pop 0 for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

     Rj data if vMax < Rj - vMin:
            vMax = Rj - vMin
         vMax < Rj - vMin vMax Rj - vMin Rj vMin vMax = Rj - vMin vMax Rj - vMin Rj vMin if vMin > Rj:
            vMin = Rj

     vMin > Rj vMin Rj vMin = Rj vMin Rj print(vMax) print vMax def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst) input_data n = int(input()) n int(input()) int input() input int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input lst = [int(input()) for i in range(n)] lst [int(input()) for i in range(n)] return (n , lst) (n , lst) n lst if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop(0)

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax) def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop(0)

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax) main def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst) def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst) input_data
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop(0)

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()