process.stdin.resume();
process.stdin.setEncoding('utf8');

// Here your code !
function main (input) {
    input = input.trim().split('\n').map(Number);
    
    var n = input[0]
    var rList = input.slice(1);
    var result = rList[1] - rList[0];
    var min = - rList[0];
    
    rList.forEach(function (v) {
        result = Math.max(result, v - min);
        min = Math.min(min, v);
    });
    console.log(result)
}

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