import sys

def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit


if __name__ == "__main__":
    solve() import sys sys def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit solve n = int(raw_input()) n int(raw_input()) int raw_input() raw_input R = [] R [] for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

     i xrange(n) xrange n R.append(int(raw_input())) R.append R append int(raw_input()) int raw_input() raw_input max_profit = -sys.maxint max_profit -sys.maxint sys.maxint sys maxint min_R = R[0] min_R R[0] R 0 for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

     i xrange(1, n) xrange 1 n if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
         R[i] - min_R > max_profit R[i] - min_R R[i] R i min_R max_profit max_profit = R[i] - min_R max_profit R[i] - min_R R[i] R i min_R if min_R > R[i]:
            min_R = R[i]

     min_R > R[i] min_R R[i] R i min_R = R[i] min_R R[i] R i print if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit solve
import sys

def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit


if __name__ == "__main__":
    solve()