def max_benefit(num_list):
    max_num = 10**9*-1
    min_num = num_list[0]

    for i in range(1,len(num_list)):
        max_num = max(max_num,num_list[i]-min_num)
        min_num = min(num_list[i],min_num)
    return max_num

n = int(input())
num_list = []
for _ in range(n):
    num_list.append(int(input()))

ans = max_benefit(num_list)
print(ans) def max_benefit(num_list):
    max_num = 10**9*-1
    min_num = num_list[0]

    for i in range(1,len(num_list)):
        max_num = max(max_num,num_list[i]-min_num)
        min_num = min(num_list[i],min_num)
    return max_num max_benefit max_num = 10**9*-1 max_num 10**9*-1 10**9 10 9 -1 min_num = num_list[0] min_num num_list[0] num_list 0 for i in range(1,len(num_list)):
        max_num = max(max_num,num_list[i]-min_num)
        min_num = min(num_list[i],min_num)
     i range(1,len(num_list)) range 1 len(num_list) len num_list max_num = max(max_num,num_list[i]-min_num) max_num max(max_num,num_list[i]-min_num) max max_num num_list[i]-min_num num_list[i] num_list i min_num min_num = min(num_list[i],min_num) min_num min(num_list[i],min_num) min num_list[i] num_list i min_num return max_num max_num num_list num_list n = int(input()) n int(input()) int input() input num_list = [] num_list [] for _ in range(n):
    num_list.append(int(input())) _ range(n) range n num_list.append(int(input())) num_list.append num_list append int(input()) int input() input ans = max_benefit(num_list) ans max_benefit(num_list) max_benefit num_list print(ans) print ans n = int(input()) int(input()) n def max_benefit(num_list):
    max_num = 10**9*-1
    min_num = num_list[0]

    for i in range(1,len(num_list)):
        max_num = max(max_num,num_list[i]-min_num)
        min_num = min(num_list[i],min_num)
    return max_num def max_benefit(num_list):
    max_num = 10**9*-1
    min_num = num_list[0]

    for i in range(1,len(num_list)):
        max_num = max(max_num,num_list[i]-min_num)
        min_num = min(num_list[i],min_num)
    return max_num max_benefit num_list = [] [] num_list ans = max_benefit(num_list) max_benefit(num_list) ans
def max_benefit(num_list):
    max_num = 10**9*-1
    min_num = num_list[0]

    for i in range(1,len(num_list)):
        max_num = max(max_num,num_list[i]-min_num)
        min_num = min(num_list[i],min_num)
    return max_num

n = int(input())
num_list = []
for _ in range(n):
    num_list.append(int(input()))

ans = max_benefit(num_list)
print(ans)
