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
38
39
40
41
42
43
44
#include<bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<=(e);i++)
#define FORD(i,s,e) for(int i=(s);i>=(e);i--)
#define ALL(k) (k).begin(),(k).end()
#define e1 first
#define e2 second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long LL;
const bool print = false;



main(){
	int n; scanf("%d", &n);
	vector<int> V;
	FOR(i, 1, n){
		int a; scanf("%d",&a);
		V.pb(a);
	}
	sort(ALL(V));
	reverse(ALL(V));
	int biggest = 0;
	int biggestCount = 0;
	while(!V.empty()){
		int a = V.back(); V.pop_back();
		while(biggest < a && biggestCount > 0){
			biggest ++;
			biggestCount >>= 1;
		}
		if(biggest < a) biggest = a;
		if(a == biggest){
			biggestCount ++;
			continue;
		}
	}
	while(biggestCount > 0){
		biggest ++;
		biggestCount >>= 1;
	}
	printf("%d\n", biggest - 1);
}