#include <bits/stdc++.h>
using namespace std;
vector<int> f(int x) {
  vector<int> bb;
  while (x) {
    bb.push_back(x % 10);
    x /= 10;
  }
  reverse(bb.begin(), bb.end());
  return bb;
}
int dp[81][4001][11];
int f(int a[], int ind, int n, int rem, int st) {
  if (ind == n) {
    return rem;
  }
  int ans = 0;
  if (dp[ind][rem][st] != -1) return dp[ind][rem][st];
  int xx = f(a, ind + 1, n, rem, st);
  int ff = 1;
  ans = max(ans, xx);
  while (ff * a[ind] <= rem) {
    ans = max(ans, f(a, ind + 1, n, rem - ff * a[ind], st + ff));
    ff++;
  }
  ff = 1;
  while (ff <= st) {
    ans = max(ans, f(a, ind + 1, n, rem + a[ind] * ff, st - ff));
    ff++;
  }
  return dp[ind][rem][st] = ans;
}
int main() {
  int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    memset(dp, -1, sizeof(dp));
    int ans = f(a, 0, n, 1000, 0);
    cout << ans;
  }
}
