#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = (0); i < (N); i++) cin >> A[i];
  int ans = 0;
  int mx = 0;
  for (auto i : A) {
    mx = max(mx, i);
    ans = max(ans, mx - i);
  }
  cout << ans << '\n';
  return 0;
}
