#include <bits/stdc++.h>
using namespace std;
int main() {
  priority_queue<long long, vector<long long>, greater<long long> > q;
  map<long long, long long> mp;
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) {
      long long x;
      scanf("%I64d", &x);
      mp[x]++;
    }
  }
  map<long long, long long>::iterator it;
  long long cnt = 0;
  for (it = mp.begin(); it != mp.end(); it++) {
    long long a = it->first, b = it->second;
    int x = b - 1;
    if (x == 0) continue;
    if (x % 2 != 0) {
      cnt++;
      x++;
    }
    mp[a + 1] += x / 2;
  }
  printf("%I64d\n", mp.rbegin()->first + 1 - mp.size() + cnt);
  return 0;
}
