# -*- coding: utf-8 -*-
"""
Created on Fri Jun 16 18:45:04 2017

@author: syaga
"""

if __name__ == "__main__":
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    max = a[1] - a[0]
    mini = a[0]
    for i in range(1, len(a)):
        diff = a[i] - mini
        if diff > max:
            max = diff
        if mini > a[i]:
            mini = a[i]
    print(max) """
Created on Fri Jun 16 18:45:04 2017

@author: syaga
""" if __name__ == "__main__":
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    max = a[1] - a[0]
    mini = a[0]
    for i in range(1, len(a)):
        diff = a[i] - mini
        if diff > max:
            max = diff
        if mini > a[i]:
            mini = a[i]
    print(max) __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input a = [] a [] for i in range(n):
        a.append(int(input()))
     i range(n) range n a.append(int(input())) a.append a append int(input()) int input() input max = a[1] - a[0] max a[1] - a[0] a[1] a 1 a[0] a 0 mini = a[0] mini a[0] a 0 for i in range(1, len(a)):
        diff = a[i] - mini
        if diff > max:
            max = diff
        if mini > a[i]:
            mini = a[i]
     i range(1, len(a)) range 1 len(a) len a diff = a[i] - mini diff a[i] - mini a[i] a i mini if diff > max:
            max = diff
         diff > max diff max max = diff max diff if mini > a[i]:
            mini = a[i]
     mini > a[i] mini a[i] a i mini = a[i] mini a[i] a i print(max) print max max = a[1] - a[0] a[1] - a[0] max n = int(input()) int(input()) n mini = a[i] a[i] mini max = diff diff max mini = a[0] a[0] mini a = [] [] a diff = a[i] - mini a[i] - mini diff
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 16 18:45:04 2017

@author: syaga
"""

if __name__ == "__main__":
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    max = a[1] - a[0]
    mini = a[0]
    for i in range(1, len(a)):
        diff = a[i] - mini
        if diff > max:
            max = diff
        if mini > a[i]:
            mini = a[i]
    print(max)