#include <bits/stdc++.h>
using namespace std;
int A[100005];
map<int, int> mymap;
int main() {
  int n;
  map<int, int>::iterator it;
  int d;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    mymap[A[i]]++;
    d = A[i];
    while (mymap[d] % 2 == 0) {
      mymap[d + 1]++;
      mymap[d] = mymap[d] - 2;
      d = d + 1;
    }
  }
  int c = 0;
  for (it = mymap.begin(); it != mymap.end(); it++) {
    if (it->second == 1) c++;
  }
  it--;
  cout << it->first - c + 1 << "\n";
  return 0;
}
