#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
const double EPS = 1e-10;
template <typename T>
void view(T e) {
  cout << e << endl;
}
template <typename T>
void view(const vector<T>& v) {
  for (const auto& e : v) {
    cout << e << " ";
  }
  cout << endl;
}
template <typename T>
void view(const vector<vector<T> >& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int N;
  cin >> N;
  vi A(N);
  for (int& a : A) cin >> a;
  vvi dp(N + 1, vi(21, -1));
  dp[0][0] = 1000;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < 21; j++) {
      dp[i + 1][j] = dp[i][j];
    }
    for (int j = 20; j > 0; j--) {
      if (dp[i + 1][j] != -1) chmax(dp[i + 1][j - 1], dp[i + 1][j] + A[i]);
    }
    for (ll j = 0; j < 20; j++) {
      if (dp[i + 1][j] >= A[i]) chmax(dp[i + 1][j + 1], dp[i + 1][j] - A[i]);
    }
  }
  cout << dp[N][0] << endl;
  return 0;
}
