#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  int i, j, k, l, n, m;
  vector<int> arr;
  int zerobit = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> j;
    mp[j]++;
    if (mp[j] == 1) arr.push_back(j);
  }
  sort(arr.begin(), arr.end());
  int ex = 0, minus = 0;
  ;
  for (i = 0; i < arr.size(); i++) {
    while (ex && minus < arr[i]) {
      zerobit += !(ex & 1);
      ex >>= 1;
      minus++;
    }
    if (minus == arr[i]) {
      ex += mp[arr[i]];
    } else {
      zerobit += arr[i] - minus;
      minus = arr[i];
      ex = mp[arr[i]];
    }
  }
  while (ex) {
    zerobit += !(ex & 1);
    ex >>= 1;
  }
  cout << zerobit << endl;
  return 0;
}
