'use strict';
(function (stdin) {
    const [n, ...R] = stdin.toString().trim().split('\n').map(Number);
    let minv = R[0], maxv = R[1] - R[0];
    for (let idx = 1; idx < n; idx++) {
        maxv = (maxv > R[idx] - minv) ? maxv : R[idx] - minv;
        minv = (minv < R[idx]) ? minv : R[idx];
    }
    console.log(maxv);
})(require('fs').readFileSync('/dev/stdin', 'UTF-8'));

