def main():
    N = int(input())
    R = tuple(int(input()) for _ in range(N))

    min_ = float('inf')
    max_ = -float('inf')
    for i in range(N):
        max_ = max(max_, R[i] - min_)
        min_ = min(min_, R[i])

    print(max_)

main() def main():
    N = int(input())
    R = tuple(int(input()) for _ in range(N))

    min_ = float('inf')
    max_ = -float('inf')
    for i in range(N):
        max_ = max(max_, R[i] - min_)
        min_ = min(min_, R[i])

    print(max_) main N = int(input()) N int(input()) int input() input R = tuple(int(input()) for _ in range(N)) R tuple(int(input()) for _ in range(N)) tuple int(input()) int input() input min_ = float('inf') min_ float('inf') float 'inf' max_ = -float('inf') max_ -float('inf') float('inf') float 'inf' for i in range(N):
        max_ = max(max_, R[i] - min_)
        min_ = min(min_, R[i])

     i range(N) range N max_ = max(max_, R[i] - min_) max_ max(max_, R[i] - min_) max max_ R[i] - min_ R[i] R i min_ min_ = min(min_, R[i]) min_ min(min_, R[i]) min min_ R[i] R i print(max_) print max_ main() main def main():
    N = int(input())
    R = tuple(int(input()) for _ in range(N))

    min_ = float('inf')
    max_ = -float('inf')
    for i in range(N):
        max_ = max(max_, R[i] - min_)
        min_ = min(min_, R[i])

    print(max_) def main():
    N = int(input())
    R = tuple(int(input()) for _ in range(N))

    min_ = float('inf')
    max_ = -float('inf')
    for i in range(N):
        max_ = max(max_, R[i] - min_)
        min_ = min(min_, R[i])

    print(max_) main
def main():
    N = int(input())
    R = tuple(int(input()) for _ in range(N))

    min_ = float('inf')
    max_ = -float('inf')
    for i in range(N):
        max_ = max(max_, R[i] - min_)
        min_ = min(min_, R[i])

    print(max_)

main()