import math

n=int(input())
t=int(input())
mint=t
t1=int(input())
if t1<t: mint=t1
maxtt=t1-t

for i in range(2,n):
    t=int(input())

    if t-mint>maxtt: maxtt=t-mint
    if t<mint: mint=t

print(int(maxtt)) import math math n=int(input()) n int(input()) int input() input t=int(input()) t int(input()) int input() input mint=t mint t t1=int(input()) t1 int(input()) int input() input if t1<t: mint=t1 t1<t t1 t maxtt=t1-t maxtt t1-t t1 t for i in range(2,n):
    t=int(input())

    if t-mint>maxtt: maxtt=t-mint
    if t<mint: mint=t i range(2,n) range 2 n t=int(input()) t int(input()) int input() input if t-mint>maxtt: maxtt=t-mint
     t-mint>maxtt t-mint t mint maxtt if t<mint: mi t<mint t mint print(int(maxtt)) print int(maxtt) int maxtt mint=t t mint t1=int(input()) int(input()) t1 t=int(input()) int(input()) t n=int(input()) int(input()) n t=int(input()) int(input()) t maxtt=t1-t t1-t maxtt
import math

n=int(input())
t=int(input())
mint=t
t1=int(input())
if t1<t: mint=t1
maxtt=t1-t

for i in range(2,n):
    t=int(input())

    if t-mint>maxtt: maxtt=t-mint
    if t<mint: mint=t

print(int(maxtt))
