function main(input){
  let lines = input.split("\n");
  let N = lines[0].split(" ")[0];
  let s = 1<<30;
  s = (s-1) * 2;
  let ret = -s;
  for(let i = 1; i <= N; i++){
    ret = Math.max(ret, Number(lines[i]) - s);
    s = Math.min(s, Number(lines[i]));
  }
  console.log(ret);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));

