function Main(input) {
  input = input.split("\n");
  var money = - Infinity;
  var tmp = input[input[0]];
  for(let i = input[0]-1; i > 0; i--) {
    money = Math.max(money, tmp - Number(input[i]));
    tmp = Math.max(tmp, Number(input[i]));
  }
  console.log(money);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

