#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> ar(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  vector<int> postMax(n, 0);
  int Max = ar[n - 1];
  postMax[n - 1] = Max;
  for (int i = n - 2; i >= 0; i--) {
    if (ar[i] >= Max) {
      Max = ar[i];
    }
    postMax[i] = Max;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ar[i] <= postMax[i]) ans = max(ans, postMax[i] - ar[i]);
  }
  cout << ans;
  return 0;
}
