debug = False

if debug:import time
if debug:start = time.time()

n = int(input())
R = [0]*n
R_min = 10**9

for i in range(n):
    R[i] = int(input())

maximum_profit = -10**9
for i in range(1, n):
    R_min = R[i-1] if R[i-1] < R_min else R_min
    profit = R[i] - R_min
    maximum_profit = profit if profit > maximum_profit else maximum_profit
print(maximum_profit)

if debug:print(time.time() - start) debug = False debug False if debug:import time debug if debug:start = time.time() debug n = int(input()) n int(input()) int input() input R = [0]*n R [0]*n [0] 0 n R_min = 10**9 R_min 10**9 10 9 for i in range(n):
    R[i] = int(input()) i range(n) range n R[i] = int(input()) R[i] R i int(input()) int input() input maximum_profit = -10**9 maximum_profit -10**9 -10 9 for i in range(1, n):
    R_min = R[i-1] if R[i-1] < R_min else R_min
    profit = R[i] - R_min
    maximum_profit = profit if profit > maximum_profit else maximum_profit i range(1, n) range 1 n R_min = R[i-1] if R[i-1] < R_min else R_min R_min R[i-1] if R[i-1] < R_min else R_min R[i-1] < R_min R[i-1] R i-1 i 1 R_min R[i-1] R i-1 i 1 R_min profit = R[i] - R_min profit R[i] - R_min R[i] R i R_min maximum_profit = profit if profit > maximum_profit else maximum_profit maximum_profit profit if profit > maximum_profit else maximum_profit profit > maximum_profit profit maximum_profit profit maximum_profit print(maximum_profit) print maximum_profit if debug:print(time.time() - start) debug maximum_profit = profit if profit > maximum_profit else maximum_profit profit if profit > maximum_profit else maximum_profit maximum_profit n = int(input()) int(input()) n R = [0]*n [0]*n R profit = R[i] - R_min R[i] - R_min profit maximum_profit = -10**9 -10**9 maximum_profit R_min = 10**9 10**9 R_min R_min = R[i-1] if R[i-1] < R_min else R_min R[i-1] if R[i-1] < R_min else R_min R_min debug = False False debug
debug = False

if debug:import time
if debug:start = time.time()

n = int(input())
R = [0]*n
R_min = 10**9

for i in range(n):
    R[i] = int(input())

maximum_profit = -10**9
for i in range(1, n):
    R_min = R[i-1] if R[i-1] < R_min else R_min
    profit = R[i] - R_min
    maximum_profit = profit if profit > maximum_profit else maximum_profit
print(maximum_profit)

if debug:print(time.time() - start)