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

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