# coding: utf-8

def getint():
    return int(input().rstrip())

def main():
    n = getint()

    values = []
    for i in range(n):
        values.append(getint())

    maxv = values[1] - values[0]
    minv = values[0]
    for j in range(1,n):
        maxv = max(maxv, values[j]-minv)
        minv = min(minv, values[j])

    print(maxv)
    
if __name__ == '__main__':
    main() def getint():
    return int(input().rstrip()) getint return int(input().rstrip()) int(input().rstrip()) int input().rstrip() ().rstrip () input rstrip def main():
    n = getint()

    values = []
    for i in range(n):
        values.append(getint())

    maxv = values[1] - values[0]
    minv = values[0]
    for j in range(1,n):
        maxv = max(maxv, values[j]-minv)
        minv = min(minv, values[j])

    print(maxv)
     main n = getint() n getint() getint values = [] values [] for i in range(n):
        values.append(getint())

     i range(n) range n values.append(getint()) values.append values append getint() getint maxv = values[1] - values[0] maxv values[1] - values[0] values[1] values 1 values[0] values 0 minv = values[0] minv values[0] values 0 for j in range(1,n):
        maxv = max(maxv, values[j]-minv)
        minv = min(minv, values[j])

     j range(1,n) range 1 n maxv = max(maxv, values[j]-minv) maxv max(maxv, values[j]-minv) max maxv values[j]-minv values[j] values j minv minv = min(minv, values[j]) minv min(minv, values[j]) min minv values[j] values j print(maxv) print maxv if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def getint():
    return int(input().rstrip()) def getint():
    return int(input().rstrip()) getint def main():
    n = getint()

    values = []
    for i in range(n):
        values.append(getint())

    maxv = values[1] - values[0]
    minv = values[0]
    for j in range(1,n):
        maxv = max(maxv, values[j]-minv)
        minv = min(minv, values[j])

    print(maxv)
     def main():
    n = getint()

    values = []
    for i in range(n):
        values.append(getint())

    maxv = values[1] - values[0]
    minv = values[0]
    for j in range(1,n):
        maxv = max(maxv, values[j]-minv)
        minv = min(minv, values[j])

    print(maxv)
     main
# coding: utf-8

def getint():
    return int(input().rstrip())

def main():
    n = getint()

    values = []
    for i in range(n):
        values.append(getint())

    maxv = values[1] - values[0]
    minv = values[0]
    for j in range(1,n):
        maxv = max(maxv, values[j]-minv)
        minv = min(minv, values[j])

    print(maxv)
    
if __name__ == '__main__':
    main()