#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

class Soultion {
 private:
  std::vector<int> prices_;
 public:
  explicit Soultion(std::vector<int>&& prices) {
    prices_ = std::forward<std::vector<int>>(prices);
  }
  int getMaxProfit() {
    int max_profit = 0;
    int min_prices = prices_[0];
    for (auto p : prices_) {
        max_profit = std::max(max_profit, p - min_prices);
        min_prices = std::min(min_prices, p);
    }
    return max_profit;
  }
};

int main() {
    int n;
    std::cin >> n;
    std::vector<int> prices;
    while (n-- >= 1) {
        int p;
        std::cin >> p;
        prices.push_back(p);
    }
    std::cout << Soultion(std::move(prices)).getMaxProfit();
}
// 64 位输出请用 printf("%lld")