#include <iostream>
#include <cassert>

using namespace std;

int main(int argc, char const *argv[]) {
  int count;
  cin >> count;
  int *nums = new int[count];
  for (int i = 0; i < count; i++) {
    cin >> nums[i];
  }

  assert(count >= 2);
  if (count < 2) {
    return 1;
  }

  int maxprofit = - nums[0];
  int maxprofit_buy = nums[0];
  int min_buy = nums[0];

  for(int i = 1; i < count; i++){
    int profit = nums[i] - min_buy;
    if (maxprofit < profit){
      maxprofit_buy = min_buy;
    }
    if(nums[i] < min_buy){
      min_buy = nums[i];
    }
    profit = nums[i] - maxprofit_buy;
    if (maxprofit < profit){
      maxprofit = profit;
    }
  }
  cout << maxprofit << endl;

  delete [] nums;
  return 0;
}
