#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n;
priority_queue<int, vector<int>, greater<int> > P;
void solve() {
  vector<int> p;
  while (!P.empty()) {
    int x = P.top();
    P.pop();
    if (!P.empty()) {
      int y = P.top();
      if (x == y) {
        P.pop();
        P.push(x + 1);
      } else {
        p.push_back(x);
      }
    } else {
      p.push_back(x);
    }
  }
  cout << (p.back() - (int)p.size() + 1) << endl;
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      int a;
      scanf("%d", &a);
      P.push(a);
    }
    solve();
  }
}
