#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long n,m=10000000000,M=-10000000000,r;
  cin >> n;
  for(int i=0; i<n; i++) {
      cin >> r;
      M=max(M,r-m);
      m=min(m,r);
  }
  cout << M << endl;
}
