const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = list.shift() | 0;

let diffMax = 0;
let current = list[0];
for (let i = 1; i < n; i++) {
  const value = list[i] | 0;
  current = current > value ? value : current;
  const diff = value - current;
  diffMax = diffMax < diff ? diff : diffMax;
}
console.log(diffMax);

