def getsub(arr):
    minv = arr[0]
    maxdist = arr[1] - minv

    for v in arr[1:]:
        # update maxdist
        maxdist = max(maxdist, v- minv)

        # update minv
        minv = min(minv, v)

    return maxdist

def main():
    # get input
    N = int(input())
    arr = [int(input()) for i in range(N)]

    # get sub
    print(getsub(arr))

if __name__ == '__main__':
    main() def getsub(arr):
    minv = arr[0]
    maxdist = arr[1] - minv

    for v in arr[1:]:
        # update maxdist
        maxdist = max(maxdist, v- minv)

        # update minv
        minv = min(minv, v)

    return maxdist getsub minv = arr[0] minv arr[0] arr 0 maxdist = arr[1] - minv maxdist arr[1] - minv arr[1] arr 1 minv for v in arr[1:]:
        # update maxdist
        maxdist = max(maxdist, v- minv)

        # update minv
        minv = min(minv, v)

     v arr[1:] arr 1: 1 maxdist = max(maxdist, v- minv) maxdist max(maxdist, v- minv) max maxdist v- minv v minv minv = min(minv, v) minv min(minv, v) min minv v return maxdist maxdist arr arr def main():
    # get input
    N = int(input())
    arr = [int(input()) for i in range(N)]

    # get sub
    print(getsub(arr)) main N = int(input()) N int(input()) int input() input int(input()) for i in range(N) for i in range(N) i range(N) range N for i in range(N) int(input()) int input() input arr = [int(input()) for i in range(N)] arr [int(input()) for i in range(N)] print(getsub(arr)) print getsub(arr) getsub arr if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def getsub(arr):
    minv = arr[0]
    maxdist = arr[1] - minv

    for v in arr[1:]:
        # update maxdist
        maxdist = max(maxdist, v- minv)

        # update minv
        minv = min(minv, v)

    return maxdist def getsub(arr):
    minv = arr[0]
    maxdist = arr[1] - minv

    for v in arr[1:]:
        # update maxdist
        maxdist = max(maxdist, v- minv)

        # update minv
        minv = min(minv, v)

    return maxdist getsub def main():
    # get input
    N = int(input())
    arr = [int(input()) for i in range(N)]

    # get sub
    print(getsub(arr)) def main():
    # get input
    N = int(input())
    arr = [int(input()) for i in range(N)]

    # get sub
    print(getsub(arr)) main
def getsub(arr):
    minv = arr[0]
    maxdist = arr[1] - minv

    for v in arr[1:]:
        # update maxdist
        maxdist = max(maxdist, v- minv)

        # update minv
        minv = min(minv, v)

    return maxdist

def main():
    # get input
    N = int(input())
    arr = [int(input()) for i in range(N)]

    # get sub
    print(getsub(arr))

if __name__ == '__main__':
    main()