import sys

def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for v in map(int, sys.stdin.readlines()):
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)

    print(max_profit)

if __name__ == '__main__':
    get_maximum_profit() import sys sys def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for v in map(int, sys.stdin.readlines()):
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)

    print(max_profit) get_maximum_profit element_number = int(input()) element_number int(input()) int input() input v0 = int(input()) v0 int(input()) int input() input v1 = int(input()) v1 int(input()) int input() input min_v = min(v0, v1) min_v min(v0, v1) min v0 v1 max_profit = v1-v0 max_profit v1-v0 v1 v0 for v in map(int, sys.stdin.readlines()):
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)

     v map(int, sys.stdin.readlines()) map int sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines max_profit = max(max_profit, v-min_v) max_profit max(max_profit, v-min_v) max max_profit v-min_v v min_v min_v = min(min_v, v) min_v min(min_v, v) min min_v v print(max_profit) print max_profit if __name__ == '__main__':
    get_maximum_profit() __name__ == '__main__' __name__ '__main__' get_maximum_profit() get_maximum_profit def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for v in map(int, sys.stdin.readlines()):
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)

    print(max_profit) def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for v in map(int, sys.stdin.readlines()):
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)

    print(max_profit) get_maximum_profit
import sys

def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for v in map(int, sys.stdin.readlines()):
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)

    print(max_profit)

if __name__ == '__main__':
    get_maximum_profit()