var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
lines.shift();

var result = 0;
var min = 1000000001;
for (var i = 0; i < lines.length; i++) {
	if (lines[i] < min)
		min = lines[i];
	if (lines[i] - min > result)
		result = lines[i] - min;
}

console.log(result);