#include<iostream>
using namespace std;

int main()
{
	int n, p;
	cin >> n;
	int max = -100000000000, min;
	cin >> min;
	for (int i = 1; i < n; i++)
	{
		cin >> p;
		if (p - min > max) max = p - min;
		if (p < min) min = p;
	}
	cout << max << endl;
}
