from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
p_r_j = None
for j,r_j in enumerate(rv):
    if p_r_j == None or p_r_j < r_j:
        p_r_j = r_j
    if p_r_j > r_j:
        continue
    r_i = min(r[:-(j+1)])
    t = r_j - r_i
    if m == None or t > m:
        m = t
print(m) from sys import stdin n = int(input()) n int(input()) int input() input int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input r=[int(input()) for i in range(n)] r [int(input()) for i in range(n)] rv = r[::-1][:-1] rv r[::-1][:-1] [::-1] r ::-1 -1 :-1 -1 m = None m None p_r_j = None p_r_j None for j,r_j in enumerate(rv):
    if p_r_j == None or p_r_j < r_j:
        p_r_j = r_j
    if p_r_j > r_j:
        continue
    r_i = min(r[:-(j+1)])
    t = r_j - r_i
    if m == None or t > m:
        m = t j r_j enumerate(rv) enumerate rv if p_r_j == None or p_r_j < r_j:
        p_r_j = r_j
     p_r_j == None or p_r_j < r_j p_r_j == None p_r_j None p_r_j < r_j p_r_j r_j p_r_j = r_j p_r_j r_j if p_r_j > r_j:
        continue
     p_r_j > r_j p_r_j r_j continue r_i = min(r[:-(j+1)]) r_i min(r[:-(j+1)]) min r[:-(j+1)] r :-(j+1) -(j+1) j+1 j 1 t = r_j - r_i t r_j - r_i r_j r_i if m == None or t > m:
        m = t m == None or t > m m == None m None t > m t m m = t m t print(m) print m m = t t m m = None None m p_r_j = None None p_r_j t = r_j - r_i r_j - r_i t n = int(input()) int(input()) n rv = r[::-1][:-1] r[::-1][:-1] rv r=[int(input()) for i in range(n)] [int(input()) for i in range(n)] r p_r_j = r_j r_j p_r_j r_i = min(r[:-(j+1)]) min(r[:-(j+1)]) r_i
from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
p_r_j = None
for j,r_j in enumerate(rv):
    if p_r_j == None or p_r_j < r_j:
        p_r_j = r_j
    if p_r_j > r_j:
        continue
    r_i = min(r[:-(j+1)])
    t = r_j - r_i
    if m == None or t > m:
        m = t
print(m)