'use strict';

const main = input => {
  input = input
    .split('\n')
    .map(v => v.trim())
    .filter(v => v)
    .map(Number);
  input.shift();

  let maxProfit = input[1] - input[0];
  let min = input.shift();

  input.forEach(R => {
    maxProfit = Math.max(R - min, maxProfit);
    min = Math.min(R, min);
  });

  console.log(maxProfit);
};

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

