const input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
let n = Number(input[0]);
input.shift();
let R = input.map(Number);
let maxv = R[1] - R[0];
let minv = R[0];
for(let j = 1; j <= n - 1; j++) {
    if (maxv < R[j] - minv) {
        maxv = R[j] - minv;
    }
    if (minv > R[j]) {
        minv = R[j];
    }
}
console.log(maxv);
 
