var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n").map(Number); 

var N = Arr[0];

var getMaxProfit = (num,array) => {
    var minR = array[1];
    var maxR = array[2] - array[1];
    
    for(let i =2; i <= num; i++){
        maxR = (maxR<(array[i]-minR)) ? (array[i]-minR) : maxR;
        minR = (minR < array[i]) ? minR : array[i];
    }
    
    return maxR;
}

console.log(getMaxProfit(N,Arr));
