def main() :
    n = int(input())
    nums = []
    for i in range(n) :
        x = int(input())
        nums.append(x)

    max = float("-inf")
    min = nums[0]
    for i in range(1,n) :
        if nums[i] - min > max :
            max = nums[i] - min

        if nums[i] < min :
            min = nums[i]


    print(max)



if __name__ == '__main__' :
    main()