#include <bits/stdc++.h>
using namespace std;
int const mod = 1000000007;
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long int m = a[n - 1], ans = 0;
  for (int i = n - 2; i >= 0; i--) {
    m = max(a[i], m);
    ans = max(ans, m - a[i]);
  }
  cout << ans;
}
