#!/usr/bin/env python

# -*- coding: utf-8 -*-

"""

?????§?????????

FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????

????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???

(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????



???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???

??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????

?±??????????????????????

"""

import math



# ?????????

n = int(input().strip())

a = []

for i in range(n):

    a.append(int(input().strip()))



min = a[0]

cnt = -1000000000

for j in range(1,n):

    x = a[j] - min

    if cnt < x:

        cnt = x

#    print("cnt={0} min={1} Rj={2}".format(cnt,min,a[j]))

    if min > a[j]:

        min = a[j]

print(cnt)
#!/usr/bin/env python

# -*- coding: utf-8 -*-

"""

?????§?????????

FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????

????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???

(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????



???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???

??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????

?±??????????????????????

"""

import math



# ?????????

cnt = -1000000000



n = int(input().strip())

min = int(input().strip())



for i in range(1,n):

    a =int(input().strip())

    x = a - min

    if cnt < x:

        cnt = x

    if min > a:

        min = a

print(cnt)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????§?????????
FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????
???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????
?±??????????????????????
"""
import math

# ?????????
n = int(input().strip())
a = []
for i in range(n):
    a.append(int(input().strip()))
min = a[0]
cnt = -1000000000
for j in range(1, n):
    x = a[j] - min
    if cnt < x:
        cnt = x
    #    print("cnt={0} min={1} Rj={2}".format(cnt,min,a[j]))
    if min > a[j]:
        min = a[j]
print(cnt)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????§?????????
FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????
???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????
?±??????????????????????
"""
import math

# ?????????
cnt = -1000000000
n = int(input().strip())
min = int(input().strip())
for i in range(1, n):
    a = int(input().strip())
    x = a - min
    if cnt < x:
        cnt = x
    if min > a:
        min = a
print(cnt)

+cnt = -1000000000 -a = [] -for i in range(n): -    a.append(int(input().strip())) -min = a[0] -cnt = -1000000000 -for j in range(1, n): -    x = a[j] - min +min = int(input().strip()) +for i in range(1, n): +    a = int(input().strip()) +    x = a - min -    #    print("cnt={0} min={1} Rj={2}".format(cnt,min,a[j])) -    if min > a[j]: -        min = a[j] +    if min > a: +        min = a