from sys import stdin
 
inf = 10**9 + 1

def solve():
    n = int(stdin.readline())
    max_d = -inf
    min_v = inf * 2

    for i in range(n):
        r = int(stdin.readline())

        max_d = max(max_d, r - min_v)
        min_v = min(min_v, r)

    print(max_d)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
 
if __name__ == '__main__':
    solve() from sys import stdin inf = 10**9 + 1 inf 10**9 + 1 10**9 10 9 1 def solve():
    n = int(stdin.readline())
    max_d = -inf
    min_v = inf * 2

    for i in range(n):
        r = int(stdin.readline())

        max_d = max(max_d, r - min_v)
        min_v = min(min_v, r)

    print(max_d) solve n = int(stdin.readline()) n int(stdin.readline()) int stdin.readline() stdin.readline stdin readline max_d = -inf max_d -inf inf min_v = inf * 2 min_v inf * 2 inf 2 for i in range(n):
        r = int(stdin.readline())

        max_d = max(max_d, r - min_v)
        min_v = min(min_v, r)

     i range(n) range n r = int(stdin.readline()) r int(stdin.readline()) int stdin.readline() stdin.readline stdin readline max_d = max(max_d, r - min_v) max_d max(max_d, r - min_v) max max_d r - min_v r min_v min_v = min(min_v, r) min_v min(min_v, r) min min_v r print(max_d) print max_d def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
  debug for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
  name val table.items() table.items table items if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
  x is val x val print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) print 'DEBUG:{} -> {}'.format(name, val) 'DEBUG:{} -> {}'.format 'DEBUG:{} -> {}' format name val file=sys.stderr file sys.stderr sys stderr return None None x x table table if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve inf = 10**9 + 1 10**9 + 1 inf def solve():
    n = int(stdin.readline())
    max_d = -inf
    min_v = inf * 2

    for i in range(n):
        r = int(stdin.readline())

        max_d = max(max_d, r - min_v)
        min_v = min(min_v, r)

    print(max_d) def solve():
    n = int(stdin.readline())
    max_d = -inf
    min_v = inf * 2

    for i in range(n):
        r = int(stdin.readline())

        max_d = max(max_d, r - min_v)
        min_v = min(min_v, r)

    print(max_d) solve def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
  def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
  debug
from sys import stdin
 
inf = 10**9 + 1

def solve():
    n = int(stdin.readline())
    max_d = -inf
    min_v = inf * 2

    for i in range(n):
        r = int(stdin.readline())

        max_d = max(max_d, r - min_v)
        min_v = min(min_v, r)

    print(max_d)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
 
if __name__ == '__main__':
    solve()