# -*- coding: utf-8 -*-
num = int(raw_input())
a = int(raw_input())
b = int(raw_input())
diff = b - a
pre_min = min(a,b)

counter = 2
while counter < num:
    current_num = int(raw_input())
    if diff < current_num - pre_min:
        diff = current_num - pre_min
    if pre_min > current_num:
        pre_min = current_num
    counter += 1

print diff num = int(raw_input()) num int(raw_input()) int raw_input() raw_input a = int(raw_input()) a int(raw_input()) int raw_input() raw_input b = int(raw_input()) b int(raw_input()) int raw_input() raw_input diff = b - a diff b - a b a pre_min = min(a,b) pre_min min(a,b) min a b counter = 2 counter 2 while counter < num:
    current_num = int(raw_input())
    if diff < current_num - pre_min:
        diff = current_num - pre_min
    if pre_min > current_num:
        pre_min = current_num
    counter += 1 counter < num counter num current_num = int(raw_input()) current_num int(raw_input()) int raw_input() raw_input if diff < current_num - pre_min:
        diff = current_num - pre_min
     diff < current_num - pre_min diff current_num - pre_min current_num pre_min diff = current_num - pre_min diff current_num - pre_min current_num pre_min if pre_min > current_num:
        pre_min = current_num
     pre_min > current_num pre_min current_num pre_min = current_num pre_min current_num counter += 1 counter 1 print a = int(raw_input()) int(raw_input()) a diff = b - a b - a diff num = int(raw_input()) int(raw_input()) num counter = 2 2 counter current_num = int(raw_input()) int(raw_input()) current_num pre_min = min(a,b) min(a,b) pre_min b = int(raw_input()) int(raw_input()) b diff = current_num - pre_min current_num - pre_min diff pre_min = current_num current_num pre_min counter += 1 1 counter
# -*- coding: utf-8 -*-
num = int(raw_input())
a = int(raw_input())
b = int(raw_input())
diff = b - a
pre_min = min(a,b)

counter = 2
while counter < num:
    current_num = int(raw_input())
    if diff < current_num - pre_min:
        diff = current_num - pre_min
    if pre_min > current_num:
        pre_min = current_num
    counter += 1

print diff