import sys

n = int(raw_input())

min_R = int(raw_input())
nums = map(int, sys.stdin.readlines())

ans = -10**9

for num in nums:
    if num - min_R > ans:
        ans = num - min_R
    if num < min_R:
        min_R = num
        
print ans import sys sys n = int(raw_input()) n int(raw_input()) int raw_input() raw_input min_R = int(raw_input()) min_R int(raw_input()) int raw_input() raw_input nums = map(int, sys.stdin.readlines()) nums map(int, sys.stdin.readlines()) map int sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines ans = -10**9 ans -10**9 -10 9 for num in nums:
    if num - min_R > ans:
        ans = num - min_R
    if num < min_R:
        min_R = num
         num nums if num - min_R > ans:
        ans = num - min_R
     num - min_R > ans num - min_R num min_R ans ans = num - min_R ans num - min_R num min_R if num < min_R:
        min_R = num
         num < min_R num min_R min_R = num min_R num print min_R = int(raw_input()) int(raw_input()) min_R nums = map(int, sys.stdin.readlines()) map(int, sys.stdin.readlines()) nums n = int(raw_input()) int(raw_input()) n ans = -10**9 -10**9 ans min_R = num num min_R ans = num - min_R num - min_R ans
import sys

n = int(raw_input())

min_R = int(raw_input())
nums = map(int, sys.stdin.readlines())

ans = -10**9

for num in nums:
    if num - min_R > ans:
        ans = num - min_R
    if num < min_R:
        min_R = num
        
print ans