#include <iostream>
using namespace std;

int n;

int main()
{
	cin >> n;
    int m; cin >> m;

    int res = 0;

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


