function main(input){
    const lines = input.split('\n');
    const length = parseInt(lines[0]);
    const nums = lines.slice(1,-1);
    let min=parseInt(nums[0]);
    let max=parseInt(nums[1])-parseInt(nums[0])
    
    for(let i=1;i<length;i++){
        let diff = parseInt(nums[i])-min;
        if(diff>max){
            max = diff;
        }
        if(min>parseInt(nums[i])){
            min = nums[i];
        }

    }
    console.log(max);
    
    
}

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