def calc_max_profit(data):
    """
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
    :param data: ??????????????????
    :return:
    """
    maxv = data[1] - data[0]
    minv = data[0]
    for j in range(1, len(data)):
        maxv = max(maxv, data[j] - minv)
        minv = min(minv, data[j])
    return maxv


if __name__ == '__main__':
    # ???????????\???
    num = int(input())
    data = []
    for i in range(num):
        data.append(int(input()))
    # data = [5, 3, 1, 3, 4, 3]
    # data = [4, 3, 2]

    # ??????
    result = calc_max_profit(data)

    # ???????????????
    print('{0}'.format(result)) def calc_max_profit(data):
    """
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
    :param data: ??????????????????
    :return:
    """
    maxv = data[1] - data[0]
    minv = data[0]
    for j in range(1, len(data)):
        maxv = max(maxv, data[j] - minv)
        minv = min(minv, data[j])
    return maxv calc_max_profit """
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
    :param data: ??????????????????
    :return:
    """ maxv = data[1] - data[0] maxv data[1] - data[0] data[1] data 1 data[0] data 0 minv = data[0] minv data[0] data 0 for j in range(1, len(data)):
        maxv = max(maxv, data[j] - minv)
        minv = min(minv, data[j])
     j range(1, len(data)) range 1 len(data) len data maxv = max(maxv, data[j] - minv) maxv max(maxv, data[j] - minv) max maxv data[j] - minv data[j] data j minv minv = min(minv, data[j]) minv min(minv, data[j]) min minv data[j] data j return maxv maxv data data if __name__ == '__main__':
    # ???????????\???
    num = int(input())
    data = []
    for i in range(num):
        data.append(int(input()))
    # data = [5, 3, 1, 3, 4, 3]
    # data = [4, 3, 2]

    # ??????
    result = calc_max_profit(data)

    # ???????????????
    print('{0}'.format(result)) __name__ == '__main__' __name__ '__main__' num = int(input()) num int(input()) int input() input data = [] data [] for i in range(num):
        data.append(int(input()))
    # data = [5, 3, 1, 3, 4, 3]
    # data = [4, 3, 2]

    # ??????
     i range(num) range num data.append(int(input())) data.append data append int(input()) int input() input result = calc_max_profit(data) result calc_max_profit(data) calc_max_profit data print('{0}'.format(result)) print '{0}'.format(result) '{0}'.format '{0}' format result result = calc_max_profit(data) calc_max_profit(data) result def calc_max_profit(data):
    """
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
    :param data: ??????????????????
    :return:
    """
    maxv = data[1] - data[0]
    minv = data[0]
    for j in range(1, len(data)):
        maxv = max(maxv, data[j] - minv)
        minv = min(minv, data[j])
    return maxv def calc_max_profit(data):
    """
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
    :param data: ??????????????????
    :return:
    """
    maxv = data[1] - data[0]
    minv = data[0]
    for j in range(1, len(data)):
        maxv = max(maxv, data[j] - minv)
        minv = min(minv, data[j])
    return maxv calc_max_profit num = int(input()) int(input()) num data = [] [] data
def calc_max_profit(data):
    """
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
    :param data: ??????????????????
    :return:
    """
    maxv = data[1] - data[0]
    minv = data[0]
    for j in range(1, len(data)):
        maxv = max(maxv, data[j] - minv)
        minv = min(minv, data[j])
    return maxv


if __name__ == '__main__':
    # ???????????\???
    num = int(input())
    data = []
    for i in range(num):
        data.append(int(input()))
    # data = [5, 3, 1, 3, 4, 3]
    # data = [4, 3, 2]

    # ??????
    result = calc_max_profit(data)

    # ???????????????
    print('{0}'.format(result))