function main(lines) {
    const n = lines.split('\n')[0]
    const rn = lines.split('\n').slice(1).map(Number)
    let max = rn[1] - rn[0];
    let min = rn[0];
    for(let i=1; i<n; i++){
        max = Math.max(rn[i]-min, max)
        min = Math.min(rn[i],min)
    }
    console.log(max)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
