#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 5;
int a[maxn], n;
int dp[85][4005][55];
int dfs(int step, int m, int s) {
  int &x = dp[step][m][s];
  if (step == n + 1) return x = m;
  if (~x) return x;
  int ans = 0;
  ans = dfs(step + 1, m, s);
  int t = m / a[step];
  for (int i = 1; i <= t; i++) {
    ans = max(ans, dfs(step + 1, m - i * a[step], s + i));
  }
  for (int i = 1; i <= s; i++) {
    ans = max(ans, dfs(step + 1, m + i * a[step], s - i));
  }
  return x = ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) cin >> a[i];
  cout << dfs(1, 1000, 0) << endl;
  return 0;
}
