let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', function() {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => Number(str.replace(/\s*$/, '')));

    maximumProfit(inputString.slice(1));
});

const maximumProfit = (arr) => {
  let profit = null;
  
  let buy = arr[0];
  for (let i=1; i<arr.length; i++) {
    const sell = arr[i];
    const p = sell - buy;
    if (profit === null || profit < p) {
      profit = p;
    }
    if (sell < buy) {
      buy = sell;
    }
  }
  
  console.log(profit);
};
