#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    mp[x]++;
  }
  int last = -1;
  int ans = 0;
  map<int, int>::iterator it = mp.begin(), itr = mp.end();
  while (it != itr) {
    int cur = (*it).first;
    if (((*it).second > 1)) {
      mp[cur + 1] += (*it).second / 2;
      mp[cur] = (*it).second % 2;
    }
    if (mp[cur]) {
      ans += cur - last - 1;
      last = cur;
    }
    it++;
  }
  printf("%d\n", ans);
}
