#include <iostream>
using namespace std;

int main() {
	int num, in, min = 2147483647, max = -2147483647;
	cin >> num;
	for (int i = 0; i < num; i++) {
		cin >> in;
		if (max < in - min) max = in - min;
		if (min > in) min = in;
	}

	cout << max << endl;
	return 0;
}
