import sys


def read_data():
    r_data = []
    n = int(sys.stdin.readline().strip())
    
    for _ in range(n):
        r = int(sys.stdin.readline().strip())
        r_data.append(r)

    return n, r_data
    
def main():
    n, r_data = read_data()
    maxv = -1000000000
    minv = r_data[0]
    
    for j in range(1, n):
        if r_data[j] - minv > maxv:
            maxv = r_data[j] - minv

        if r_data[j] < minv:
            minv = r_data[j]

    print(maxv)

if __name__ == '__main__':
    main() import sys sys def read_data():
    r_data = []
    n = int(sys.stdin.readline().strip())
    
    for _ in range(n):
        r = int(sys.stdin.readline().strip())
        r_data.append(r)

    return n, r_data
     read_data r_data = [] r_data [] n = int(sys.stdin.readline().strip()) n int(sys.stdin.readline().strip()) int sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip for _ in range(n):
        r = int(sys.stdin.readline().strip())
        r_data.append(r)

     _ range(n) range n r = int(sys.stdin.readline().strip()) r int(sys.stdin.readline().strip()) int sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip r_data.append(r) r_data.append r_data append r return n, r_data return n, r_data n r_data def main():
    n, r_data = read_data()
    maxv = -1000000000
    minv = r_data[0]
    
    for j in range(1, n):
        if r_data[j] - minv > maxv:
            maxv = r_data[j] - minv

        if r_data[j] < minv:
            minv = r_data[j]

    print(maxv) main n, r_data = read_data() n read_data() read_data r_data maxv = -1000000000 maxv -1000000000 minv = r_data[0] minv r_data[0] r_data 0 for j in range(1, n):
        if r_data[j] - minv > maxv:
            maxv = r_data[j] - minv

        if r_data[j] < minv:
            minv = r_data[j]

     j range(1, n) range 1 n if r_data[j] - minv > maxv:
            maxv = r_data[j] - minv

         r_data[j] - minv > maxv r_data[j] - minv r_data[j] r_data j minv maxv maxv = r_data[j] - minv maxv r_data[j] - minv r_data[j] r_data j minv if r_data[j] < minv:
            minv = r_data[j]

     r_data[j] < minv r_data[j] r_data j minv minv = r_data[j] minv r_data[j] r_data j print(maxv) print maxv if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def read_data():
    r_data = []
    n = int(sys.stdin.readline().strip())
    
    for _ in range(n):
        r = int(sys.stdin.readline().strip())
        r_data.append(r)

    return n, r_data
     def read_data():
    r_data = []
    n = int(sys.stdin.readline().strip())
    
    for _ in range(n):
        r = int(sys.stdin.readline().strip())
        r_data.append(r)

    return n, r_data
     read_data def main():
    n, r_data = read_data()
    maxv = -1000000000
    minv = r_data[0]
    
    for j in range(1, n):
        if r_data[j] - minv > maxv:
            maxv = r_data[j] - minv

        if r_data[j] < minv:
            minv = r_data[j]

    print(maxv) def main():
    n, r_data = read_data()
    maxv = -1000000000
    minv = r_data[0]
    
    for j in range(1, n):
        if r_data[j] - minv > maxv:
            maxv = r_data[j] - minv

        if r_data[j] < minv:
            minv = r_data[j]

    print(maxv) main
import sys


def read_data():
    r_data = []
    n = int(sys.stdin.readline().strip())
    
    for _ in range(n):
        r = int(sys.stdin.readline().strip())
        r_data.append(r)

    return n, r_data
    
def main():
    n, r_data = read_data()
    maxv = -1000000000
    minv = r_data[0]
    
    for j in range(1, n):
        if r_data[j] - minv > maxv:
            maxv = r_data[j] - minv

        if r_data[j] < minv:
            minv = r_data[j]

    print(maxv)

if __name__ == '__main__':
    main()