#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T, class S>
ostream &operator<<(ostream &o, const pair<T, S> &p) {
  return o << '(' << p.first << ", " << p.second << ')';
}
template <template <class, class...> class T, class... A>
typename enable_if<!is_same<T<A...>, string>(), ostream &>::type operator<<(
    ostream &o, T<A...> V) {
  o << '[';
  for (auto a : V) o << a << ", ";
  return o << ']';
}
map<long long int, long long int> ct;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin >> n;
  for (long long int i = 0; i < (n); i++) {
    long long int x;
    cin >> x;
    ct[x]++;
  }
  long long int popct = 0, maxbit = -1;
  while (!ct.empty()) {
    pair<long long int, long long int> p = *ct.begin();
    ct.erase(p.first);
    if (p.second & 1) {
      popct++;
      maxbit = p.first;
    }
    if (p.second >= 2) ct[p.first + 1] += p.second / 2;
  }
  cout << maxbit + 1 - popct;
}
