#coding: utf-8
#ALDS1_1D
import sys

n=int(raw_input())
minv=float("inf")
maxv=float("-inf")
for i in xrange(1,n+1):
 r=int(raw_input())
 maxv=max(maxv,r-minv)
 minv=min(minv,r)

print maxv import sys sys n=int(raw_input()) n int(raw_input()) int raw_input() raw_input minv=float("inf") minv float("inf") float "inf" maxv=float("-inf") maxv float("-inf") float "-inf" for i in xrange(1,n+1):
 r=int(raw_input())
 maxv=max(maxv,r-minv)
 minv=min(minv,r) i xrange(1,n+1) xrange 1 n+1 n 1 r=int(raw_input()) r int(raw_input()) int raw_input() raw_input maxv=max(maxv,r-minv) maxv max(maxv,r-minv) max maxv r-minv r minv minv=min(minv,r) minv min(minv,r) min minv r print maxv=float("-inf") float("-inf") maxv maxv=max(maxv,r-minv) max(maxv,r-minv) maxv minv=min(minv,r) min(minv,r) minv n=int(raw_input()) int(raw_input()) n minv=float("inf") float("inf") minv r=int(raw_input()) int(raw_input()) r
#coding: utf-8
#ALDS1_1D
import sys

n=int(raw_input())
minv=float("inf")
maxv=float("-inf")
for i in xrange(1,n+1):
 r=int(raw_input())
 maxv=max(maxv,r-minv)
 minv=min(minv,r)

print maxv