function main() {
  var n = input[0];
  var maxv = -1000000000;
  var profit;
  for (j = 1; j <= n; j++) {
    for (i = 1; i <= j - 1; i++) {
      profit = input[j] - input[i];
      maxv = Math.max(maxv, profit);
    }
  }
  console.log(maxv);
}

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();
});