#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<int> a(n);
  if (n == 0) {
    cout << "0";
    return 0;
  }
  for (int i = 0; i < n; i++) cin >> a[i];
  long long m = a[n - 1], c = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] >= m) {
      m = a[i];
    } else {
      c = max(c, m - a[i]);
    }
  }
  cout << c;
}
