function main(_stdin) {
    const stdin = _stdin.split('\n').filter(e => e.length).map(Number);
    const len = stdin.shift();

    let min =  stdin[0];
    let diff =  stdin[1] - stdin[0];
    stdin.shift();

    stdin.forEach(e => {
        diff = Math.max(diff, e - min);
        min = Math.min(min, e);
    });

    console.log(diff);
}

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

