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

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)

m()

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


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)


m()

-if "__main__" == __name__: -    m() +m()