#include <bits/stdc++.h>
using namespace std;
int maxProfit(int price[], int start, int end, long long int &yen) {
  if (end <= start) return 0;
  int profit = 0;
  for (int i = start; i < end; i++) {
    for (int j = i + 1; j <= end; j++) {
      if (price[j] > price[i]) {
        int curr_profit = yen + price[j] - price[i] +
                          maxProfit(price, start, i - 1, yen) +
                          maxProfit(price, j + 1, end, yen);
        profit = max(profit, curr_profit);
      }
    }
  }
  return profit;
}
int main() {
  int n;
  cin >> n;
  int price[n];
  for (int i = 0; i < n; i++) {
    cin >> price[i];
  }
  long long int yen = 1000;
  long long int prof;
  prof = maxProfit(price, 0, n - 1, yen);
  if (prof >= 1000)
    cout << prof;
  else
    cout << 1000;
  return 0;
}
