function main() {
  var n = input[0];
  var maxv = -1000000000;
  var minv = input[1];
  for (j = 2; j <= n; j++) {
    maxv = Math.max(maxv, input[j] - minv);
    minv = Math.min(minv, input[j]);
    console.log("maxv = " + maxv + ": minv = " + minv);
  }
  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();
});