#!/usr/bin/env python
# -*- coding: utf-8 -*-


def maxprofit(n, rs):
    maxp = rs[1] - rs[0]
    minp = rs[0]
    for i in range(1, n):
        maxp = max(maxp, rs[i] - minp)
        minp = min(minp, rs[i])
    return maxp


def main():
    n = int(input())
    rs = [int(input()) for i in range(n)]
    print(maxprofit(n, rs))

if __name__ == "__main__":
    main() def maxprofit(n, rs):
    maxp = rs[1] - rs[0]
    minp = rs[0]
    for i in range(1, n):
        maxp = max(maxp, rs[i] - minp)
        minp = min(minp, rs[i])
    return maxp maxprofit maxp = rs[1] - rs[0] maxp rs[1] - rs[0] rs[1] rs 1 rs[0] rs 0 minp = rs[0] minp rs[0] rs 0 for i in range(1, n):
        maxp = max(maxp, rs[i] - minp)
        minp = min(minp, rs[i])
     i range(1, n) range 1 n maxp = max(maxp, rs[i] - minp) maxp max(maxp, rs[i] - minp) max maxp rs[i] - minp rs[i] rs i minp minp = min(minp, rs[i]) minp min(minp, rs[i]) min minp rs[i] rs i return maxp maxp n n rs rs def main():
    n = int(input())
    rs = [int(input()) for i in range(n)]
    print(maxprofit(n, rs)) main n = int(input()) n int(input()) int input() input int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input rs = [int(input()) for i in range(n)] rs [int(input()) for i in range(n)] print(maxprofit(n, rs)) print maxprofit(n, rs) maxprofit n rs if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def maxprofit(n, rs):
    maxp = rs[1] - rs[0]
    minp = rs[0]
    for i in range(1, n):
        maxp = max(maxp, rs[i] - minp)
        minp = min(minp, rs[i])
    return maxp def maxprofit(n, rs):
    maxp = rs[1] - rs[0]
    minp = rs[0]
    for i in range(1, n):
        maxp = max(maxp, rs[i] - minp)
        minp = min(minp, rs[i])
    return maxp maxprofit def main():
    n = int(input())
    rs = [int(input()) for i in range(n)]
    print(maxprofit(n, rs)) def main():
    n = int(input())
    rs = [int(input()) for i in range(n)]
    print(maxprofit(n, rs)) main
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def maxprofit(n, rs):
    maxp = rs[1] - rs[0]
    minp = rs[0]
    for i in range(1, n):
        maxp = max(maxp, rs[i] - minp)
        minp = min(minp, rs[i])
    return maxp


def main():
    n = int(input())
    rs = [int(input()) for i in range(n)]
    print(maxprofit(n, rs))

if __name__ == "__main__":
    main()