#include <bits/stdc++.h>
using namespace std;
int temp;
map<int, int> mmap;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> temp;
    mmap[temp]++;
  }
  for (map<int, int>::iterator it = mmap.begin(); it != mmap.end(); it++) {
    int cc = it->second;
    int idx = it->first;
    mmap[idx++] = cc % 2;
    cc /= 2;
    while (cc != 0) {
      mmap[idx++] += (cc % 2);
      cc /= 2;
    }
  }
  int maxidx = -1;
  int hasone = 0;
  for (map<int, int>::iterator it = mmap.begin(); it != mmap.end(); it++) {
    int cc = it->second;
    int idx = it->first;
    if (idx > maxidx) {
      maxidx = idx;
    }
    if (cc == 1) {
      hasone++;
    }
  }
  cout << (maxidx - hasone + 1) << endl;
  return 0;
}
