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 = - Number.MAX_VALUE;
    var max = - Number.MAX_VALUE;
    
    for (var i = 0; i < n; i ++) {
        max = Math.max.apply(null, rList.slice(i + 1));
        result = Math.max(result, max - rList[i]);
    }
    console.log(result)
}

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