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

#define REP(i, n) for (int i=0, ___=(n); i<___; ++i)
#define FOR(i, a, b) for (int i=(a), ___=(b); i<=___; ++i)

int read() { int n; cin >> n; return n; }

int v[222222];

int main() {
	int n = read();
	int res = -1;
	while (n--) {
		int x = read();
		while (v[x] == 1) {
			v[x] = 0;
			++x;
		}
		v[x] = 1;
		res = std::max(res, x);
	}

	cout << res << "\n";

	return 0;
}