# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

max_profit = lst[1] - lst[0]
min_value = min(lst[0], lst[1])

for i in range(2, N):
    price = lst[i]
    max_profit = max(max_profit, price - min_value)
    min_value = min(min_value, price)

print(max_profit) import sys sys import os os import math math N = int(input()) N int(input()) int input() input lst = [] lst [] for i in range(N):
    lst.append(int(input())) i range(N) range N lst.append(int(input())) lst.append lst append int(input()) int input() input max_profit = lst[1] - lst[0] max_profit lst[1] - lst[0] lst[1] lst 1 lst[0] lst 0 min_value = min(lst[0], lst[1]) min_value min(lst[0], lst[1]) min lst[0] lst 0 lst[1] lst 1 for i in range(2, N):
    price = lst[i]
    max_profit = max(max_profit, price - min_value)
    min_value = min(min_value, price) i range(2, N) range 2 N price = lst[i] price lst[i] lst i max_profit = max(max_profit, price - min_value) max_profit max(max_profit, price - min_value) max max_profit price - min_value price min_value min_value = min(min_value, price) min_value min(min_value, price) min min_value price print(max_profit) print max_profit lst = [] [] lst min_value = min(lst[0], lst[1]) min(lst[0], lst[1]) min_value max_profit = max(max_profit, price - min_value) max(max_profit, price - min_value) max_profit min_value = min(min_value, price) min(min_value, price) min_value N = int(input()) int(input()) N max_profit = lst[1] - lst[0] lst[1] - lst[0] max_profit price = lst[i] lst[i] price
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

max_profit = lst[1] - lst[0]
min_value = min(lst[0], lst[1])

for i in range(2, N):
    price = lst[i]
    max_profit = max(max_profit, price - min_value)
    min_value = min(min_value, price)

print(max_profit)