#include <bits/stdc++.h>
using namespace std;
int ara[2 * 100007];
int main() {
  int t, tst = 1;
  int n;
  scanf("%d", &n);
  map<int, int> mp;
  for (int i = 0; i < (n); i++) {
    scanf("%d", &ara[i]);
    mp[ara[i]]++;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it->second / 2 != 0) {
      mp[it->first + 1] += it->second / 2;
      it->second -= (it->second / 2) * 2;
    }
  }
  int prev = -1, ans = 0;
  for (pair<int, int> x : mp) {
    if (x.second != 0) {
      ans += x.first - prev - 1;
      prev = x.first;
    }
  }
  printf("%d\n", ans);
  return 0;
}
