#include <iostream>
using namespace std;

int a,a0;
int n;

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

    cin >> n;
	if(n>1000000) cout << "err1 ";
    cin >> a0 >> a;
    if(a0>10000) cout << "err2 ";
    if(a>10000) cout << "err3 ";
	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;
       if(a>10000) cout << "err4 ";
	}

	cout << r << endl;
}


