#include <iostream>
using namespace std;

int a,a0;
int n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    cin >> a0 >> a;

	int r = a - a0;

	int m = a0;
	for(int i = 1; i < n; i++)
	{
	  if (a - m > r) r = a - m;
	  if (a < m) m = a;
	  if(i<n-1) cin >> a;
	}

	cout << r << endl;
}


