#include <iostream>

using namespace std;

int main(){
	int n, i, r, m, M;
	cin >> n >> m >> r;
	M = r - m;
	if(r < m) m = r;
	for(i = 2; i < n; i++){
		cin >> r;
		if(r-m > M) M = r-m;
		if(r < m) m = r;
	}
	cout << M << endl;
	return 0;
}
