/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: alex
*
* Created on October 6, 2016, 9:19 PM
*/
#include <cstdlib>
using namespace std;
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
/*
*
*/
int etsi (long long x,vector< pair<long,long> > v, long o , long d){
long long n=v.size();
long long k=0;
if(d==0){
for (long long b = n/2; b >= 1; b /= 2) {
while(k+b<n&&v.at(k+b).first<x){
k+=b;
}
}
if(k<v.size()-1&&v.at(k+1).first==x){
k++;
}
}else{
k=d;
}
while(o!=-1&&v.at(k)>=v.at(o)){
k--;
if(k<0){
return 0;
}
}
if(k<0){
return 0;
}
if(v.at(k).first>x){
return 0;
}
if(x-v.at(k).first*v.at(k).second<v.at(k).first) {
return 1;
}
for (int i = v.at(k).second; i > 0; i--) {
int pa= etsi(x-v.at(k).first*i,v,k,0);
if(pa==1){
return 1;
}
}
return 0;
}
int main(int argc, char** argv) {
long long n;
cin >> n;
long long l[n];
long long a;
long long j=0;
vector< pair<long long,long long> > v;
for (int i = 0; i < n; i++) {
cin >> a;
l[i]=a;
}
sort(l, l+n);
a=l[0];
long long r=1;
long long f;
for (int i = 1; i < n; i++) {
f=l[i];
if(f==a){
r++;
a=f;
}else{
pair <long long,long long> p=make_pair(a,r);
v.push_back(p);
j++;
a=f;
r=1;
}
}
pair <long long,long long> p=make_pair(a,r);
v.push_back(p);
long long i=1;
long long q =0;
while(etsi(i,v,-1,q)){
q=0;
i++;
long long n=v.size();
long long k=0;
for (long long b = n/2; b >= 1; b /= 2) {
while(k+b<n&&v.at(k+b).first<i){
k+=b;
}
}
if(k<v.size()-1&&v.at(k+1).first==i){
k++;
i=v.at(k).first*v.at(k).second+i;
}else{
q=k;
}
}
cout << i;
return 0;
}