def main():

    n = int(eval(input()))



    nums = []

    for i in range(n):

        nums.append(int(eval(input())))



    rj = max(nums[1:])

    r  = rj - nums[0]



    for i in range(1, n-1):

        ri = nums[i]



        if ri == rj:

            rj = max(nums[i+1:])



        r = max(r, rj-ri)



    print(r)



if __name__ == '__main__':

    main()
def main():

    n = int(eval(input()))



    r  = 0

    ri = 0



    for i in range(n):

        m = int(eval(input()))



        if 0 == i:

            ri = m

            continue



        if 1 == i:

            r = m - ri



        r  = max(r, m - ri)

        ri = min(ri, m)



    print(r)



if __name__ == '__main__':

    main()
def main():
    n = int(eval(input()))
    nums = []
    for i in range(n):
        nums.append(int(eval(input())))
    rj = max(nums[1:])
    r = rj - nums[0]
    for i in range(1, n - 1):
        ri = nums[i]
        if ri == rj:
            rj = max(nums[i + 1 :])
        r = max(r, rj - ri)
    print(r)


if __name__ == "__main__":
    main()

def main():
    n = int(eval(input()))
    r = 0
    ri = 0
    for i in range(n):
        m = int(eval(input()))
        if 0 == i:
            ri = m
            continue
        if 1 == i:
            r = m - ri
        r = max(r, m - ri)
        ri = min(ri, m)
    print(r)


if __name__ == "__main__":
    main()

-    nums = [] +    r = 0 +    ri = 0 -        nums.append(int(eval(input()))) -    rj = max(nums[1:]) -    r = rj - nums[0] -    for i in range(1, n - 1): -        ri = nums[i] -        if ri == rj: -            rj = max(nums[i + 1 :]) -        r = max(r, rj - ri) +        m = int(eval(input())) +        if 0 == i: +            ri = m +            continue +        if 1 == i: +            r = m - ri +        r = max(r, m - ri) +        ri = min(ri, m)