function main() {
  const n = parseInt(input.shift(), 10);
  const prices = input.map(function(x) {
    return parseInt(x, 10);
  });
  let max = -1000000000;
  let min = 100000000;
  for (let i = 0; i < prices.length; i++) {
    min = Math.min(min, prices[i]);
    max = Math.max(max, prices[i] - min);
  }
  console.log(max);

}

var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  input.pop();
  main();
});