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
#include <iostream>

const int M = 201720;
char tab[M];

int solve(int n) {
  for(int i = 0; i < n; i++) {
    int a;
    std::cin >> a;

    if(tab[a] == 0) {
      tab[a] = 1;
    } else {
      int b = a;
      while(tab[b] != 0) {
        tab[b] = 0;
        b++;
      }
      tab[b] = 1;
    }
  }

  for(int i = M; i >= 0; i--) {
    if(tab[i] != 0) {
      return i;
    }
  }

  return -1;
}

int main() {
  int n;
  std::cin >> n;

  int sol = solve(n);

  std::cout << sol << std::endl;

  return 0;
}