n = int(input())
ns = []
max_profit = -1000000000
min_value = int(input())
for i in range(1,n):
    num = int(input())
    max_profit = max(max_profit, num-min_value)
    min_value = min(num, min_value)
print(max_profit)
     n = int(input()) n int(input()) int input() input ns = [] ns [] max_profit = -1000000000 max_profit -1000000000 min_value = int(input()) min_value int(input()) int input() input for i in range(1,n):
    num = int(input())
    max_profit = max(max_profit, num-min_value)
    min_value = min(num, min_value) i range(1,n) range 1 n num = int(input()) num int(input()) int input() input max_profit = max(max_profit, num-min_value) max_profit max(max_profit, num-min_value) max max_profit num-min_value num min_value min_value = min(num, min_value) min_value min(num, min_value) min num min_value print(max_profit) print max_profit max_profit = max(max_profit, num-min_value) max(max_profit, num-min_value) max_profit ns = [] [] ns num = int(input()) int(input()) num min_value = int(input()) int(input()) min_value max_profit = -1000000000 -1000000000 max_profit min_value = min(num, min_value) min(num, min_value) min_value n = int(input()) int(input()) n
n = int(input())
ns = []
max_profit = -1000000000
min_value = int(input())
for i in range(1,n):
    num = int(input())
    max_profit = max(max_profit, num-min_value)
    min_value = min(num, min_value)
print(max_profit)
    
