import sys



n = int(eval(input()))

minv = int(eval(input()))

maxv = -1000000000



for r in map(int,sys.stdin.readlines()):

  if maxv < r-minv < 0:

    maxv = r-minv

    minv = r

  elif maxv < r-minv:

    maxv = r-minv

  elif r-minv < 0:

    minv = r



print(maxv)
import sys

 

n = int(eval(input()))

minv = int(eval(input()))

maxv = -1000000000

 

for r in map(int,sys.stdin.readlines()):

  m = r-minv

  if maxv < m: 

    maxv = m

    if m < 0: minv = r

  elif m < 0: minv = r

 

print(maxv)
import sys

n = int(eval(input()))
minv = int(eval(input()))
maxv = -1000000000
for r in map(int, sys.stdin.readlines()):
    if maxv < r - minv < 0:
        maxv = r - minv
        minv = r
    elif maxv < r - minv:
        maxv = r - minv
    elif r - minv < 0:
        minv = r
print(maxv)

import sys

n = int(eval(input()))
minv = int(eval(input()))
maxv = -1000000000
for r in map(int, sys.stdin.readlines()):
    m = r - minv
    if maxv < m:
        maxv = m
        if m < 0:
            minv = r
    elif m < 0:
        minv = r
print(maxv)

-    if maxv < r - minv < 0: -        maxv = r - minv -        minv = r -    elif maxv < r - minv: -        maxv = r - minv -    elif r - minv < 0: +    m = r - minv +    if maxv < m: +        maxv = m +        if m < 0: +            minv = r +    elif m < 0: