#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
#?????§??????
#??????????????????????????°???????????????????????¢?????´?????????????????????
def get_maximum_profit(value_list, n_list):
    minv = pow(10,10) + 1
    profit = -minv
    for v in value_list:
        profit = max(profit, v - minv) 
        minv = min(minv, v)
    return profit

def main():
    n_list = int(input())
    target_list = [int(input()) for i in range(n_list)]
    print(get_maximum_profit(target_list, n_list))
    
if __name__ == "__main__":
    main() def get_maximum_profit(value_list, n_list):
    minv = pow(10,10) + 1
    profit = -minv
    for v in value_list:
        profit = max(profit, v - minv) 
        minv = min(minv, v)
    return profit get_maximum_profit minv = pow(10,10) + 1 minv pow(10,10) + 1 pow(10,10) pow 10 10 1 profit = -minv profit -minv minv for v in value_list:
        profit = max(profit, v - minv) 
        minv = min(minv, v)
     v value_list profit = max(profit, v - minv) profit max(profit, v - minv) max profit v - minv v minv minv = min(minv, v) minv min(minv, v) min minv v return profit profit value_list value_list n_list n_list def main():
    n_list = int(input())
    target_list = [int(input()) for i in range(n_list)]
    print(get_maximum_profit(target_list, n_list))
     main n_list = int(input()) n_list int(input()) int input() input int(input()) for i in range(n_list) for i in range(n_list) i range(n_list) range n_list for i in range(n_list) int(input()) int input() input target_list = [int(input()) for i in range(n_list)] target_list [int(input()) for i in range(n_list)] print(get_maximum_profit(target_list, n_list)) print get_maximum_profit(target_list, n_list) get_maximum_profit target_list n_list if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n_list = int(input())
    target_list = [int(input()) for i in range(n_list)]
    print(get_maximum_profit(target_list, n_list))
     def main():
    n_list = int(input())
    target_list = [int(input()) for i in range(n_list)]
    print(get_maximum_profit(target_list, n_list))
     main def get_maximum_profit(value_list, n_list):
    minv = pow(10,10) + 1
    profit = -minv
    for v in value_list:
        profit = max(profit, v - minv) 
        minv = min(minv, v)
    return profit def get_maximum_profit(value_list, n_list):
    minv = pow(10,10) + 1
    profit = -minv
    for v in value_list:
        profit = max(profit, v - minv) 
        minv = min(minv, v)
    return profit get_maximum_profit
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
#?????§??????
#??????????????????????????°???????????????????????¢?????´?????????????????????
def get_maximum_profit(value_list, n_list):
    minv = pow(10,10) + 1
    profit = -minv
    for v in value_list:
        profit = max(profit, v - minv) 
        minv = min(minv, v)
    return profit

def main():
    n_list = int(input())
    target_list = [int(input()) for i in range(n_list)]
    print(get_maximum_profit(target_list, n_list))
    
if __name__ == "__main__":
    main()