1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
#include<queue>
#include<list>
#include<stdio.h>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ull unsigned long long int
#define FOR(i,n) for(int i=0;i<n;++i)
#define FORD(i,n) for(int i=(n)-1;i>=0;--i)
#define znakow 26
#define dcout 0 && cout
#define INF 9999999
int inline min(int a,int b){return a>b?b:a;}
int inline max(int a,int b){return a<b?b:a;}
int NIL=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;    
	cin>>n;
	int tr=300000;
	int*t=new int[tr];
	FOR(i,tr)t[i]=0;
	FOR(i,n){
		int a;cin>>a;
		++t[a];
		while(t[a]>1){
			t[a]=0;
			++a;
			++t[a];
		}
	}
	FORD(i,tr)if(t[i]||i==0){cout<<i<<endl;break;}
	return 0;
}