#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int dp[10005], price[MAXN];
int main() {
  int t, n = 0, m = 1000, ans;
  scanf("%d", &t);
  for (int i = 1; i <= t; ++i) {
    scanf("%d", &price[i]);
  }
  ans = m;
  for (int i = 1; i < t; ++i) {
    memset(dp, ~0x3f, sizeof(dp));
    dp[ans] = ans;
    for (int j = 1; j <= n; ++j) {
      for (int k = ans; k >= price[i]; --k) {
        dp[k - price[i]] =
            max(dp[k - price[i]], dp[k] + price[i + 1] - price[i]);
      }
    }
    int ma = 0;
    for (int j = 0; j <= ans; ++j) {
      ma = max(ma, dp[j]);
    }
    ans = ma;
  }
  cout << ans << endl;
  return 0;
}
