# encoding=utf-8
n = int(raw_input())

min = int(raw_input())  
keep = int(raw_input()) 
diff = keep - min       
if keep > min:
    keep = min
n = n - 2

for i in range(n):
    v = int(raw_input())
    if v - keep > diff:
        diff = v - keep
        min = keep
    elif keep > v:
        keep = v

print diff n = int(raw_input()) n int(raw_input()) int raw_input() raw_input min = int(raw_input()) min int(raw_input()) int raw_input() raw_input keep = int(raw_input()) keep int(raw_input()) int raw_input() raw_input diff = keep - min diff keep - min keep min if keep > min:
    keep = min keep > min keep min keep = min keep min n = n - 2 n n - 2 n 2 for i in range(n):
    v = int(raw_input())
    if v - keep > diff:
        diff = v - keep
        min = keep
    elif keep > v:
        keep = v i range(n) range n v = int(raw_input()) v int(raw_input()) int raw_input() raw_input if v - keep > diff:
        diff = v - keep
        min = keep
    elif keep > v:
        keep = v v - keep > diff v - keep v keep diff diff = v - keep diff v - keep v keep min = keep min keep elif keep > v:
        keep = v keep > v keep v keep = v keep v print min = int(raw_input()) int(raw_input()) min n = n - 2 n - 2 n keep = min min keep min = keep keep min v = int(raw_input()) int(raw_input()) v diff = v - keep v - keep diff n = int(raw_input()) int(raw_input()) n keep = v v keep diff = keep - min keep - min diff keep = int(raw_input()) int(raw_input()) keep
# encoding=utf-8
n = int(raw_input())

min = int(raw_input())  
keep = int(raw_input()) 
diff = keep - min       
if keep > min:
    keep = min
n = n - 2

for i in range(n):
    v = int(raw_input())
    if v - keep > diff:
        diff = v - keep
        min = keep
    elif keep > v:
        keep = v

print diff