import sys

x = []

for line in sys.stdin.readlines():
  x.append(line.strip())

max = -(10**9)
min = int(x[1])

for i in range(2, int(x[0])+1):
  sa = int(x[i]) - min
  if max < sa:
    max = sa
  if min > int(x[i]):
    min = int(x[i])

  

print max import sys sys x = [] x [] for line in sys.stdin.readlines():
  x.append(line.strip()) line sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines x.append(line.strip()) x.append x append line.strip() line.strip line strip max = -(10**9) max -(10**9) 10**9 10 9 min = int(x[1]) min int(x[1]) int x[1] x 1 for i in range(2, int(x[0])+1):
  sa = int(x[i]) - min
  if max < sa:
    max = sa
  if min > int(x[i]):
    min = int(x[i])

   i range(2, int(x[0])+1) range 2 int(x[0])+1 int(x[0]) int x[0] x 0 1 sa = int(x[i]) - min sa int(x[i]) - min int(x[i]) int x[i] x i min if max < sa:
    max = sa
   max < sa max sa max = sa max sa if min > int(x[i]):
    min = int(x[i])

   min > int(x[i]) min int(x[i]) int x[i] x i min = int(x[i]) min int(x[i]) int x[i] x i print x = [] [] x min = int(x[1]) int(x[1]) min max = -(10**9) -(10**9) max max = sa sa max min = int(x[i]) int(x[i]) min sa = int(x[i]) - min int(x[i]) - min sa
import sys

x = []

for line in sys.stdin.readlines():
  x.append(line.strip())

max = -(10**9)
min = int(x[1])

for i in range(2, int(x[0])+1):
  sa = int(x[i]) - min
  if max < sa:
    max = sa
  if min > int(x[i]):
    min = int(x[i])

  

print max