let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const [, ...nums] = content
    .trim()
    .split('\n')
    .map(n => +n);

  let max = null;
  let min = nums[0];
  for (let i = 1; i < nums.length; i++) {
    const bNum = nums[i];
    min = min > nums[i - 1] ? nums[i - 1] : min;
    const d = bNum - min;
    if (max === null || d > max) {
      max = d;
    }
  }

  console.log(max);
});
