#include <bits/stdc++.h>
using namespace std;
int n, i;
int a[100001];
void inp() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
}
void process() {
  int t1;
  int t2 = 0;
  t1 = a[1];
  for (i = 1; i <= n; i++) {
    t1 = min(t1, a[i]);
    t2 = max(t2, a[i] - t1);
  }
  cout << t2;
}
int main() {
  inp();
  process();
  return 0;
}
