var numbers = [];

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
input.split('\n').forEach(function(line) {
  if (line !== '') {
    numbers.push(parseInt(line.trim(), 10));
  }
});

// Eliminate the first element which describes the size of the array.
numbers.shift();

var max = numbers[1] - numbers[0];
var min = numbers[0];
for (var i = 1; i < numbers.length; i += 1) {
  max = Math.max(max, numbers[i] - min);
  min = Math.min(min, numbers[i]);
};
console.log(max);