process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  const n = Number(lines[0]);
  let minR = Number(lines[1]);
  let maxIncome = lines[2] - minR;
  for (let i = 2; i <= n; i++) {
    const r = Number(lines[i]);
    maxIncome = Math.max(maxIncome, r - minR);
    minR = Math.min(minR, r);
  }
  console.log(maxIncome);
});

