#include <bits/stdc++.h>
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const int64_t LINF = 8931145141919364364, LMOD = 998244353;
constexpr int MAX = 100000;
int64_t dp[88][MAX];
int main() {
  int n;
  cin >> n;
  int64_t a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n + 1; ++i)
    for (int j = 0; j < MAX; ++j) dp[i][j] = -LINF;
  dp[0][0] = 1000;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < MAX; ++j) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      if (j - 1 >= 0) {
        if (dp[i - 1][j - 1] - a[i - 1] >= 0) {
          dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] - a[i - 1]);
        }
        if (dp[i][j - 1] - a[i - 1] >= 0) {
          dp[i][j] = max(dp[i][j], dp[i][j - 1] - a[i - 1]);
        }
      }
    }
    for (int j = MAX - 1; j >= 0; --j) {
      if (j + 1 < MAX) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j + 1] + a[i - 1]);
        dp[i][j] = max(dp[i][j], dp[i][j + 1] + a[i - 1]);
      }
    }
  }
  cout << dp[n][0] << '\n';
  return 0;
}
