import std.stdio, std.string, std.conv, std.algorithm;

void main() {
    int n = readln.chomp.to!int;
    int[] r = new int[n];
    foreach (i; 0 .. n) {
        r[i] = readln.chomp.to!int;
    }
    int maxv = int.min;
    int minv = r[0];
    foreach (i; 1 .. n) {
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }
    maxv.writeln;
}
