#include<bits/stdc++.h>

#define int long long 
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,a,b) for (int i = a; i < b; i++)
#define f(i,n) for (int i = 0; i < n; i++)

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;

void solve(){
    int n;
    cin>>n;
    
    vector<int> v(n);

    int sum=0;

    f(i,n){
        cin>>v[i];
        sum+=v[i];
    }    

    bool dp[n+1][sum+1];
 

    for (int i = 0; i <= n; i++)
        dp[i][0] = true;
 

    for (int i = 1; i <= sum; i++)
        dp[0][i] = false;
 

    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=sum; j++)
        {
            dp[i][j] = dp[i-1][j];

            if (v[i-1] <= j)
                dp[i][j] |= dp[i-1][j-v[i-1]];
        }
    }
  

    int diff = INT_MAX;
     
    for (int j=sum/2; j>=0; j--)
    {

        if (dp[n][j] == true)
        {
            diff = sum-2*j;
            break;
        }
    }

    int ans=(sum+diff)/2;

    cout<<ans<<endl;
}

signed main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif

    solve();
    return 0; 
}    
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar('-');
  }
  while(s--){
    my_putchar(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
long long N;
long long eval(long long x){
  return ((x)*(x+1LL))>>1;
}
int main(){
  rd(N);
  long long PiIOrLma;
  long long AuJVIghY;
  long long FJNsjZ7B;
  PiIOrLma = 0;
  AuJVIghY = N;
  while(PiIOrLma < AuJVIghY){
    if((PiIOrLma + AuJVIghY)%2==0){
      FJNsjZ7B = (PiIOrLma + AuJVIghY) / 2;
    }
    else{
      FJNsjZ7B = (PiIOrLma + AuJVIghY + 1) / 2;
    }
    if(eval(FJNsjZ7B) < N){
      PiIOrLma = FJNsjZ7B;
    }
    else{
      AuJVIghY = FJNsjZ7B - 1;
    }
  }
  long long ans =AuJVIghY;
  ans = ans -2;
  chmax(ans, 0);
  while(eval(ans) < N){
    ++ ans;
  }
  wt_L(ans);
  wt_L('\n');
  return 0;
}
// cLay version 20210405-1

// --- original code ---
// //no-unlocked
// ll N;
// ll eval(ll x){
// 	return ((x)*(x+1LL))>>1;
// }
// { 
// 	rd(N);
// 	ll ans = bsearch_max[ll, k, 0, N](eval(k) < N);
// 	ans = ans -2;
// 	ans >?= 0;
// 	while(eval(ans) < N) ++ ans;
// 	wt(ans);
// }