#include <iostream>
using namespace std;

int prices[(int)1e7];
int n;

int main()
{
  cin >> n;
  for(int i=0;i<n;i++) cin >> prices[i];

  int m = prices[0], res = 0;

  for (int i = 1; i < n; i++)
  {
    m = min(m, prices[i]);
    res = max(res, prices[i] - m);
  }

  cout << res << endl;
}



