# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
sample_input = '''
3
4
3
2
'''
give_sample_input = False
if give_sample_input:
  sample_input_list = sample_input.split()
  def input():
    return sample_input_list.pop(0)

numOfData = int(input())
max_diff = None  # minus infty
min_val = None  # plus infty
prev_val = int(input())
for n in range(numOfData-1):
	val = int(input())
	if min_val is None:
		min_val = prev_val
	else:
		min_val = min(prev_val, min_val)
	if max_diff is None:
	  max_diff = val - min_val
	else:
	  max_diff = max(val - min_val, max_diff)
	prev_val = val

print(max_diff) sample_input = '''
3
4
3
2
''' sample_input '''
3
4
3
2
''' give_sample_input = False give_sample_input False if give_sample_input:
  sample_input_list = sample_input.split()
  def input():
    return sample_input_list.pop(0) give_sample_input sample_input_list = sample_input.split() sample_input_list sample_input.split() sample_input.split sample_input split def input():
    return sample_input_list.pop(0) input return sample_input_list.pop(0) sample_input_list.pop(0) sample_input_list.pop sample_input_list pop 0 numOfData = int(input()) numOfData int(input()) int input() input max_diff = None max_diff None min_val = None min_val None prev_val = int(input()) prev_val int(input()) int input() input for n in range(numOfData-1):
	val = int(input())
	if min_val is None:
		min_val = prev_val
	else:
		min_val = min(prev_val, min_val)
	if max_diff is None:
	  max_diff = val - min_val
	else:
	  max_diff = max(val - min_val, max_diff)
	prev_val = val n range(numOfData-1) range numOfData-1 numOfData 1 val = int(input()) val int(input()) int input() input if min_val is None:
		min_val = prev_val
	else:
		min_val = min(prev_val, min_val)
	 min_val is None min_val None min_val = prev_val min_val prev_val min_val = min(prev_val, min_val) min_val min(prev_val, min_val) min prev_val min_val if max_diff is None:
	  max_diff = val - min_val
	else:
	  max_diff = max(val - min_val, max_diff)
	 max_diff is None max_diff None max_diff = val - min_val max_diff val - min_val val min_val max_diff = max(val - min_val, max_diff) max_diff max(val - min_val, max_diff) max val - min_val val min_val max_diff prev_val = val prev_val val print(max_diff) print max_diff prev_val = int(input()) int(input()) prev_val sample_input_list = sample_input.split() sample_input.split() sample_input_list max_diff = max(val - min_val, max_diff) max(val - min_val, max_diff) max_diff prev_val = val val prev_val max_diff = val - min_val val - min_val max_diff def input():
    return sample_input_list.pop(0) def input():
    return sample_input_list.pop(0) input min_val = prev_val prev_val min_val numOfData = int(input()) int(input()) numOfData max_diff = None None max_diff min_val = min(prev_val, min_val) min(prev_val, min_val) min_val min_val = None None min_val give_sample_input = False False give_sample_input val = int(input()) int(input()) val sample_input = '''
3
4
3
2
''' '''
3
4
3
2
''' sample_input
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
sample_input = '''
3
4
3
2
'''
give_sample_input = False
if give_sample_input:
  sample_input_list = sample_input.split()
  def input():
    return sample_input_list.pop(0)

numOfData = int(input())
max_diff = None  # minus infty
min_val = None  # plus infty
prev_val = int(input())
for n in range(numOfData-1):
	val = int(input())
	if min_val is None:
		min_val = prev_val
	else:
		min_val = min(prev_val, min_val)
	if max_diff is None:
	  max_diff = val - min_val
	else:
	  max_diff = max(val - min_val, max_diff)
	prev_val = val

print(max_diff)