#include <bits/stdc++.h>
using namespace std;
int n;
int a[101];
int dp[101010];
int main(void) {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int sum = 1000;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j < sum + 1; ++j) dp[j] = j;
    for (int j = 0; j < sum + 1; ++j) {
      if (j - a[i] >= 0) dp[j] = max(dp[j], dp[j - a[i]] + a[i + 1]);
    }
    int mx = 0;
    for (int j = 0; j < sum + 1; ++j) mx = max(mx, dp[j]);
    sum = mx;
  }
  cout << sum << endl;
  return 0;
}
