#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    map<int, int> M;
    for (int i = 0; i < n; i++) {
      int tmp;
      scanf("%d", &tmp);
      M[tmp]++;
    }
    int p = 0, ans = 0, last = -1;
    for (map<int, int>::iterator it = M.begin(); it != M.end(); it++) {
      int val = (*it).first;
      int cnt = (*it).second;
      if (cnt > 1) M[val + 1] += cnt / 2;
      cnt %= 2;
      if (cnt != 0) {
        ans += (val - last - 1);
        last = val;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
