#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int q;
    cin >> q;
    mp[q]++;
  }
  int last = 0;
  for (auto &i : mp) {
    if (i.second > 1) {
      last = i.second / 2;
      i.second %= 2;
      mp[i.first + 1] += last;
    }
  }
  int cnt = 0;
  for (auto i : mp) {
    cnt += (i.second == 1);
  }
  auto it = mp.end();
  it--;
  int maxx = it->first;
  cout << maxx - cnt + 1 << endl;
}
