import sys



def get_maximum_profit():

    element_number = int(eval(input()))

    v0 = int(eval(input()))

    v1 = int(eval(input()))



    min_v = min(v0, v1)

    max_profit = v1-v0



    for i in range(element_number-2):

        v = int(eval(input()))

        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



def get_maximum_profit():

    element_number = int(eval(input()))

    v0 = int(eval(input()))

    v1 = int(eval(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


def get_maximum_profit():
    element_number = int(eval(input()))
    v0 = int(eval(input()))
    v1 = int(eval(input()))
    min_v = min(v0, v1)
    max_profit = v1 - v0
    for i in range(element_number - 2):
        v = int(eval(input()))
        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


def get_maximum_profit():
    element_number = int(eval(input()))
    v0 = int(eval(input()))
    v1 = int(eval(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()

-    for i in range(element_number - 2): -        v = int(eval(input())) +    for v in map(int, sys.stdin.readlines()):