function main(input){
	var n = scan();
	
	var x = [];
	rep(n, function(){
		x.push(scan());
	});

	x = x.reverse();
	y = [];
	rep(n, function(i){
		y.push(x[i - 1] - x[i]);
		x[i] = Math.max(x[i], x[i - 1]);
	}, 1);
	console.log(Math.max.apply(null, y));
}

function rep(end, func, start){
	if(start === undefined){
		start = 0;
	}
	for(var i = start; i < end; ++i){
		func(i);
	}
}

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

var input = '';

function scan(type){
	if(type === 'string'){
		return input.shift();
	}
	else{
		return +input.shift();
	}
}

function print(val){
	console.log(val);
}

process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});