#include <bits/stdc++.h>
using namespace std;
set<int, greater<int> > s;
int n, x;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    for (; s.find(x) != s.end(); s.erase(x), ++x)
      ;
    s.insert(x);
  }
  cout << *s.begin() + 1 - s.size();
  return 0;
}
