function MaxProfit(array) {
    var i = 0;
    var j = 1;
    var iMin = array[i];
    var maxProfit = Number.NEGATIVE_INFINITY;
    while (j < array.length) {
        if (array[i] < iMin) {
            iMin = array[i];
        }
        if (array[j] - iMin > maxProfit) {
            maxProfit = array[j] - iMin;
        }
        i++;
        j++;
    }
    console.log(maxProfit);
}
function main(input) {
    var array = input
        .trim()
        .split("\n")
        .map(Number);
    array.shift();
    MaxProfit(array);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

