#!/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) """
?????§?????????
FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????

???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????
?±??????????????????????
""" import math math cnt = -1000000000 cnt -1000000000 n = int(input().strip()) n int(input().strip()) int input().strip() ().strip () input strip min = int(input().strip()) min int(input().strip()) int input().strip() ().strip () 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 i range(1,n) range 1 n a =int(input().strip()) a int(input().strip()) int input().strip() ().strip () input strip x = a - min x a - min a min if cnt < x:
        cnt = x
     cnt < x cnt x cnt = x cnt x if min > a:
        min = a min > a min a min = a min a print(cnt) print cnt a =int(input().strip()) int(input().strip()) a cnt = x x cnt min = a a min min = int(input().strip()) int(input().strip()) min cnt = -1000000000 -1000000000 cnt x = a - min a - min x n = int(input().strip()) int(input().strip()) n
#!/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)