#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6
5
3
1
3
4
3

output:
3
"""

import sys


def solve():
    # write your code here
    max_profit = -1 * float('inf')
    min_stock = prices[0]
    for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
    return max_profit


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    p_num = int(_input[0])
    prices = list(map(int, _input[1:]))
    print(solve()) """
input:
6
5
3
1
3
4
3

output:
3
""" import sys sys def solve():
    # write your code here
    max_profit = -1 * float('inf')
    min_stock = prices[0]
    for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
    return max_profit solve max_profit = -1 * float('inf') max_profit -1 * float('inf') -1 float('inf') float 'inf' min_stock = prices[0] min_stock prices[0] prices 0 for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
     price prices[1:] prices 1: 1 max_profit = max(max_profit, price - min_stock) max_profit max(max_profit, price - min_stock) max max_profit price - min_stock price min_stock min_stock = min(min_stock, price) min_stock min(min_stock, price) min min_stock price return max_profit max_profit if __name__ == '__main__':
    _input = sys.stdin.readlines()
    p_num = int(_input[0])
    prices = list(map(int, _input[1:]))
    print(solve()) __name__ == '__main__' __name__ '__main__' _input = sys.stdin.readlines() _input sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines p_num = int(_input[0]) p_num int(_input[0]) int _input[0] _input 0 prices = list(map(int, _input[1:])) prices list(map(int, _input[1:])) list map(int, _input[1:]) map int _input[1:] _input 1: 1 print(solve()) print solve() solve p_num = int(_input[0]) int(_input[0]) p_num def solve():
    # write your code here
    max_profit = -1 * float('inf')
    min_stock = prices[0]
    for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
    return max_profit def solve():
    # write your code here
    max_profit = -1 * float('inf')
    min_stock = prices[0]
    for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
    return max_profit solve _input = sys.stdin.readlines() sys.stdin.readlines() _input prices = list(map(int, _input[1:])) list(map(int, _input[1:])) prices
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6
5
3
1
3
4
3

output:
3
"""

import sys


def solve():
    # write your code here
    max_profit = -1 * float('inf')
    min_stock = prices[0]
    for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
    return max_profit


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    p_num = int(_input[0])
    prices = list(map(int, _input[1:]))
    print(solve())