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
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
#define DEBUG(x) cerr << #x << " = " << x << endl;
#define REP(x, n) for(__typeof(n) x = 0; x < (n); ++x)
#define FOR(x, b, e) for(__typeof(b) x = (b); x != (e); x += 1 - 2 * ((b) > (e)))
const int INF = 1000000001;
const double EPS = 10e-9;

void add_one(vector<int>& sum, int i) {
	int j = i;
	while(sum[j] == 1) {
		sum[j] = 0;
		++j;
	}
	sum[j] = 1;
}

#ifndef CATCH_TEST
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<int> sum(1000000, 0);
	REP(x, n) {
		int m;
		cin >> m;
		add_one(sum, m);
	}
	int result = -1;
	REP(x, sum.size()) {
		if (sum[x] == 1) {
			result = x;
		}
	}

	cout << result << endl;

	return 0;
}
#endif