#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n; scanf("%d", &n);
	int a = INT_MAX, b = INT_MIN;
	rep(i, n) {
		int d; scanf("%d", &d);
		b = max(b, d - a);
		a = min(a, d);
	}
	printf("%d\n", b);
}