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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <cstring>
using namespace std;

const int MAX_VAL = 2018 * 100;

struct input {
	int ct;
	int val[MAX_VAL];
} in;

struct output {
	int res;
} out;

void clean() {
//	memset(in.val, 0, sizeof(int) * MAX_VAL);
}

void read() {
	int val;

	cin >> in.ct;
	for (int i = 0; i < in.ct; ++i) {
		cin >> val;
		++in.val[val];
	}
}

void gen() {
	in.ct = 1000 * 1000;
	in.val[0] = in.ct;
}

void solve() {
	for (int i = 0; i < MAX_VAL; ++i) {
		if(in.val[i] > 1){
			in.val[i+1] += in.val[i] / 2;
		}
	}

	for(int i = MAX_VAL-1; i >=0; --i){
		if(in.val[i] > 0){
			out.res = i;
			break;
		}
	}
}

void write() {
	cout << out.res << endl;
}

int main() {
	ios_base::sync_with_stdio(0);

	clean();
	read();
//	gen();
	solve();
	write();

	return 0;
}