#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll ans = 0;
  ll maxA = 0;
  for (int i = 0; i < (int)(N); i++) {
    cin >> A[i];
    maxA = max(maxA, A[i]);
    ans = A[i] - maxA;
  }
  cout << ans << endl;
  return 0;
}
