#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 234567;
int n, a[MAX_N];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int maxx = a[n - 1], stool_length = 0;
  for (int i = n - 2; i >= 0; --i) {
    if (a[i] > maxx) maxx = a[i];
    stool_length = max(stool_length, maxx - a[i]);
  }
  cout << stool_length << endl;
  return 0;
}
