#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n;
  cin >> n;
  long long int a[n];
  for (long int i = 0; i < n; i++) cin >> a[i];
  long long int diff = 0, pad = 0, total = 0;
  for (long int i = 1; i < n; i++) {
    for (long int j = i - 1; j >= 0; j--) {
      diff = a[i] - a[j];
      if (diff > 0 && diff > pad) pad = diff;
    }
    total += pad;
  }
  cout << pad;
}
