#cording by utf-8

n = int(input())
#maxv ?????§???
#minv ????°????
minv = int(input()) #?????????????°????
#print("minv",minv)
maxp = int(input()) #??????????????§???
maxp = maxp - minv
if maxp + minv < minv:
    minv = maxp + minv
for i in range(2,n):
    stock = int(input())
    if minv > stock:
        minv = stock
        #print("minv",minv)
    else:
        profit = stock - minv
        if profit > maxp:
            maxp = profit
            #print("maxp",maxp)

print(maxp) n = int(input()) n int(input()) int input() input minv = int(input()) minv int(input()) int input() input maxp = int(input()) maxp int(input()) int input() input maxp = maxp - minv maxp maxp - minv maxp minv if maxp + minv < minv:
    minv = maxp + minv maxp + minv < minv maxp + minv maxp minv minv minv = maxp + minv minv maxp + minv maxp minv for i in range(2,n):
    stock = int(input())
    if minv > stock:
        minv = stock
        #print("minv",minv)
    else:
        profit = stock - minv
        if profit > maxp:
            maxp = profit
            #print("maxp",maxp) i range(2,n) range 2 n stock = int(input()) stock int(input()) int input() input if minv > stock:
        minv = stock
        #print("minv",minv)
    else:
        profit = stock - minv
        if profit > maxp:
            maxp = profit
            #print("maxp",maxp) minv > stock minv stock minv = stock minv stock profit = stock - minv profit stock - minv stock minv if profit > maxp:
            maxp = profit
            #print("maxp",maxp) profit > maxp profit maxp maxp = profit maxp profit print(maxp) print maxp maxp = int(input()) int(input()) maxp maxp = maxp - minv maxp - minv maxp minv = int(input()) int(input()) minv n = int(input()) int(input()) n profit = stock - minv stock - minv profit maxp = profit profit maxp stock = int(input()) int(input()) stock minv = stock stock minv minv = maxp + minv maxp + minv minv
#cording by utf-8

n = int(input())
#maxv ?????§???
#minv ????°????
minv = int(input()) #?????????????°????
#print("minv",minv)
maxp = int(input()) #??????????????§???
maxp = maxp - minv
if maxp + minv < minv:
    minv = maxp + minv
for i in range(2,n):
    stock = int(input())
    if minv > stock:
        minv = stock
        #print("minv",minv)
    else:
        profit = stock - minv
        if profit > maxp:
            maxp = profit
            #print("maxp",maxp)

print(maxp)