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

    r  = 0
    ri = 0

    for i in range(n):
        m = int(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(input())

    r  = 0
    ri = 0

    for i in range(n):
        m = int(input())

        if 0 == i:
            ri = m
            continue

        if 1 == i:
            r = m - ri

        r  = max(r, m - ri)
        ri = min(ri, m)

    print(r) main n = int(input()) n int(input()) int input() input r  = 0 r 0 ri = 0 ri 0 for i in range(n):
        m = int(input())

        if 0 == i:
            ri = m
            continue

        if 1 == i:
            r = m - ri

        r  = max(r, m - ri)
        ri = min(ri, m)

     i range(n) range n m = int(input()) m int(input()) int input() input if 0 == i:
            ri = m
            continue

         0 == i 0 i ri = m ri m continue if 1 == i:
            r = m - ri

         1 == i 1 i r = m - ri r m - ri m ri r  = max(r, m - ri) r max(r, m - ri) max r m - ri m ri ri = min(ri, m) ri min(ri, m) min ri m print(r) print r if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = int(input())

    r  = 0
    ri = 0

    for i in range(n):
        m = int(input())

        if 0 == i:
            ri = m
            continue

        if 1 == i:
            r = m - ri

        r  = max(r, m - ri)
        ri = min(ri, m)

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

    r  = 0
    ri = 0

    for i in range(n):
        m = int(input())

        if 0 == i:
            ri = m
            continue

        if 1 == i:
            r = m - ri

        r  = max(r, m - ri)
        ri = min(ri, m)

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

    r  = 0
    ri = 0

    for i in range(n):
        m = int(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()