import sys

s=1e10;b=-s

eval(input())

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

 if b<r-s:b=r-s

 if s>r:s=r

print(b)

import sys

def m():

 s=1e10;b=-s

 eval(input())

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

  if b<r-s:b=r-s

  if s>r:s=r

 print(b)

if'__main__'==__name__:m()

import sys

s = 1e10
b = -s
eval(input())
for r in map(int, sys.stdin.readlines()):
    if b < r - s:
        b = r - s
    if s > r:
        s = r
print(b)

import sys


def m():
    s = 1e10
    b = -s
    eval(input())
    for r in map(int, sys.stdin):
        if b < r - s:
            b = r - s
        if s > r:
            s = r
    print(b)


if "__main__" == __name__:
    m()

-s = 1e10 -b = -s -eval(input()) -for r in map(int, sys.stdin.readlines()): -    if b < r - s: -        b = r - s -    if s > r: -        s = r -print(b) + +def m(): +    s = 1e10 +    b = -s +    eval(input()) +    for r in map(int, sys.stdin): +        if b < r - s: +            b = r - s +        if s > r: +            s = r +    print(b) + + +if "__main__" == __name__: +    m()