#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long prev = 0;
  long long ht = 0;
  for (int i = 0; i < n; i++) {
    long long h;
    cin >> h;
    if (h < prev) {
      ht = max(ht, prev - h);
      h = prev;
    }
    prev = h;
  }
  cout << ht << endl;
  return 0;
}
