def main():
    n = int(input())

    nums = []
    for i in range(n):
        nums.append(int(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(input())

    nums = []
    for i in range(n):
        nums.append(int(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) main n = int(input()) n int(input()) int input() input nums = [] nums [] for i in range(n):
        nums.append(int(input()))

     i range(n) range n nums.append(int(input())) nums.append nums append int(input()) int input() input rj = max(nums[1:]) rj max(nums[1:]) max nums[1:] nums 1: 1 r  = rj - nums[0] r rj - nums[0] rj nums[0] 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)

     i range(1, n-1) range 1 n-1 n 1 ri = nums[i] ri nums[i] nums i if ri == rj:
            rj = max(nums[i+1:])

         ri == rj ri rj rj = max(nums[i+1:]) rj max(nums[i+1:]) max nums[i+1:] nums i+1: i+1 i 1 r = max(r, rj-ri) r max(r, rj-ri) max r rj-ri rj ri print(r) print r if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = int(input())

    nums = []
    for i in range(n):
        nums.append(int(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) def main():
    n = int(input())

    nums = []
    for i in range(n):
        nums.append(int(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) main
def main():
    n = int(input())

    nums = []
    for i in range(n):
        nums.append(int(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()