#include <iostream>
using namespace std;

const int N=1e7+1;
int a[N];
int n;

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

    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];

	int r = a[1] - a[0];

	int m = a[0];
	for(int i = 1; i < n; i++)
	{
	  if (a[i] - m > r) r = a[i] - m;
	  if (a[i] < m) m = a[i];
	}

	cout << r << endl;
}


