#include <bits/stdc++.h>
using namespace std;
long long int ans;
int arr[300009];
vector<int> vr;
void solve() {
  int n;
  cin >> n;
  int nax = INT_MIN;
  int naxx = INT_MIN;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    nax = max(arr[i], nax);
  }
  for (int i = 0; i < n; ++i) {
    naxx = max(naxx, nax - arr[i]);
  }
  cout << naxx << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int testc = 1;
  for (int t = 0; t < testc; ++t) solve();
  return 0;
}
