from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

Given_num=int(input())
tmp_num=int(input())
minv=tmp_num
maxv=-BIG_NUM
for i in range(1,Given_num):
    tmp_num=int(input())
    maxv=max(maxv,tmp_num-minv)
    minv=min(minv,tmp_num)
print("%d"%(maxv))
 from enum import Enum import sys sys import math math BIG_NUM = 2000000000 BIG_NUM 2000000000 MOD = 1000000007 MOD 1000000007 EPS = 0.000000001 EPS 0.000000001 Given_num=int(input()) Given_num int(input()) int input() input tmp_num=int(input()) tmp_num int(input()) int input() input minv=tmp_num minv tmp_num maxv=-BIG_NUM maxv -BIG_NUM BIG_NUM for i in range(1,Given_num):
    tmp_num=int(input())
    maxv=max(maxv,tmp_num-minv)
    minv=min(minv,tmp_num) i range(1,Given_num) range 1 Given_num tmp_num=int(input()) tmp_num int(input()) int input() input maxv=max(maxv,tmp_num-minv) maxv max(maxv,tmp_num-minv) max maxv tmp_num-minv tmp_num minv minv=min(minv,tmp_num) minv min(minv,tmp_num) min minv tmp_num print("%d"%(maxv)) print "%d"%(maxv) "%d" maxv minv=tmp_num tmp_num minv tmp_num=int(input()) int(input()) tmp_num MOD = 1000000007 1000000007 MOD BIG_NUM = 2000000000 2000000000 BIG_NUM maxv=-BIG_NUM -BIG_NUM maxv maxv=max(maxv,tmp_num-minv) max(maxv,tmp_num-minv) maxv Given_num=int(input()) int(input()) Given_num minv=min(minv,tmp_num) min(minv,tmp_num) minv EPS = 0.000000001 0.000000001 EPS tmp_num=int(input()) int(input()) tmp_num
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

Given_num=int(input())
tmp_num=int(input())
minv=tmp_num
maxv=-BIG_NUM
for i in range(1,Given_num):
    tmp_num=int(input())
    maxv=max(maxv,tmp_num-minv)
    minv=min(minv,tmp_num)
print("%d"%(maxv))

