#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> v;
  map<int, int>::iterator ite;
  pair<map<int, int>::iterator, bool> pai;
  int n;
  int i;
  int a, b;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%d", &a);
    pai = v.insert(pair<int, int>(a, 1));
    if (pai.second == false) {
      pai.first->second++;
    }
  }
  for (ite = v.begin(); ite != v.end(); ite++) {
    a = ite->second;
    ite->second = a & 1;
    i = 1;
    while (1) {
      b = 1 << i;
      if (b > a) break;
      if (b & a) {
        pai = v.insert(pair<int, int>(ite->first + i, 1));
        if (pai.second == false) {
          pai.first->second++;
        }
      }
      i++;
    }
  }
  a = 0;
  for (ite = v.begin(); ite != v.end(); ite++) {
    if (ite->second != 0) a++;
    b = ite->first;
  }
  cout << b + 1 - a << endl;
}
