#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  int ans = 0, dp[n];
  dp[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) dp[i] = max(dp[i + 1], a[i]);
  for (long long i = 0; i < n; i++) ans = max(ans, dp[i] - a[i]);
  cout << ans << "\n";
  return 0;
}
