import sys
INF = (sys.maxint)/3

def MaximumProfit(R_list):
	minR = INF
	maxD = -INF
	for R in R_list:
		maxD = max(maxD, R - minR)
		minR = min(minR, R)
	return maxD

def main():
	n = input()
	R_list = []
	for i in range(n):
		R_list.append(input())
	print MaximumProfit(R_list)

if __name__ == '__main__':
	main() import sys sys INF = (sys.maxint)/3 INF (sys.maxint)/3 sys.maxint sys maxint 3 def MaximumProfit(R_list):
	minR = INF
	maxD = -INF
	for R in R_list:
		maxD = max(maxD, R - minR)
		minR = min(minR, R)
	return maxD MaximumProfit minR = INF minR INF maxD = -INF maxD -INF INF for R in R_list:
		maxD = max(maxD, R - minR)
		minR = min(minR, R)
	 R R_list maxD = max(maxD, R - minR) maxD max(maxD, R - minR) max maxD R - minR R minR minR = min(minR, R) minR min(minR, R) min minR R return maxD maxD R_list R_list def main():
	n = input()
	R_list = []
	for i in range(n):
		R_list.append(input())
	print MaximumProfit(R_list) main n = input() n input() input R_list = [] R_list [] for i in range(n):
		R_list.append(input())
	 i range(n) range n R_list.append(input()) R_list.append R_list append input() input print MaximumProfit(R_list) MaximumProfit R_list if __name__ == '__main__':
	main() __name__ == '__main__' __name__ '__main__' main() main def MaximumProfit(R_list):
	minR = INF
	maxD = -INF
	for R in R_list:
		maxD = max(maxD, R - minR)
		minR = min(minR, R)
	return maxD def MaximumProfit(R_list):
	minR = INF
	maxD = -INF
	for R in R_list:
		maxD = max(maxD, R - minR)
		minR = min(minR, R)
	return maxD MaximumProfit def main():
	n = input()
	R_list = []
	for i in range(n):
		R_list.append(input())
	print MaximumProfit(R_list) def main():
	n = input()
	R_list = []
	for i in range(n):
		R_list.append(input())
	print MaximumProfit(R_list) main INF = (sys.maxint)/3 (sys.maxint)/3 INF
import sys
INF = (sys.maxint)/3

def MaximumProfit(R_list):
	minR = INF
	maxD = -INF
	for R in R_list:
		maxD = max(maxD, R - minR)
		minR = min(minR, R)
	return maxD

def main():
	n = input()
	R_list = []
	for i in range(n):
		R_list.append(input())
	print MaximumProfit(R_list)

if __name__ == '__main__':
	main()