#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
map<int, int> m;
int main() {
  int n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (m.find(x) == m.end()) m[x] = 0;
    ++m[x];
  }
  int res = 0;
  for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
    res = it->first;
    int t = it->second;
    it->second = t % 2;
    if (t / 2) m[it->first + 1] += t / 2;
  }
  int cnt = 0;
  for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
    if (it->second) ++cnt;
  }
  cout << res + 1 - cnt << endl;
  return 0;
}
