'use strict'

const main = (input) => {
    input = input.split('\n').map(v => parseInt(v))
    const n = input[0]
    const arr = input.slice(1, n + 1)
    let max = -100000000000
    let min = arr[0]

    for(let j = 1; j < arr.length; j++){
        max = Math.max(max, arr[j] - min)
        min = Math.min(min, arr[j])
    }

    console.log(max)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))
