#include <iostream>
using namespace std;

int main() {
    int n, minv, maxv=-2000000000, R; cin >> n >> minv;
    for(int i=1;i<n;i++){
      cin >> R;
      if(maxv<R-minv) maxv=R-minv;
      if(minv>R)minv=R;
    }
    cout << maxv << endl;
    return 0;
}