var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(Number);
var n = input.shift();
var minimum = input[0];
var maximum = -Math.pow(10, 9) * 2;

for (var i = 1; i < input.length; i++) {
  maximum = Math.max(maximum, input[i] - minimum);
  minimum = Math.min(minimum, input[i]);
}

console.log(maximum);