import math

n = int(input())
minv = int(input())
maxv = -math.pow(10, 9)

for _ in range(n-1):
    rt = int(input())
    maxv = max(maxv, rt - minv)
    minv = min(minv, rt)

print(maxv) import math math n = int(input()) n int(input()) int input() input minv = int(input()) minv int(input()) int input() input maxv = -math.pow(10, 9) maxv -math.pow(10, 9) math.pow(10, 9) math.pow math pow 10 9 for _ in range(n-1):
    rt = int(input())
    maxv = max(maxv, rt - minv)
    minv = min(minv, rt) _ range(n-1) range n-1 n 1 rt = int(input()) rt int(input()) int input() input maxv = max(maxv, rt - minv) maxv max(maxv, rt - minv) max maxv rt - minv rt minv minv = min(minv, rt) minv min(minv, rt) min minv rt print(maxv) print maxv rt = int(input()) int(input()) rt minv = int(input()) int(input()) minv minv = min(minv, rt) min(minv, rt) minv maxv = max(maxv, rt - minv) max(maxv, rt - minv) maxv n = int(input()) int(input()) n maxv = -math.pow(10, 9) -math.pow(10, 9) maxv
import math

n = int(input())
minv = int(input())
maxv = -math.pow(10, 9)

for _ in range(n-1):
    rt = int(input())
    maxv = max(maxv, rt - minv)
    minv = min(minv, rt)

print(maxv)