#include <bits/stdc++.h>
using namespace std;
int a[100010];
map<int, int> m;
map<int, int>::iterator it, it2;
int main() {
  int n;
  scanf("%d", &n);
  int has = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (m.find(a[i]) != m.end()) {
      m[a[i]]++;
      m[a[i] + 1] += m[a[i]] / 2;
      m[a[i]] = m[a[i]] % 2;
      if (m[a[i]] == 0) m.erase(a[i]);
    } else
      m[a[i]] = 1;
  }
  int max = 0;
  for (it = m.begin(); it != m.end(); it++) {
    if (it->second == 1) {
      max = it->first;
      has++;
    } else {
      if (it->second % 2 == 1) has++;
      m[it->first + 1] += it->second / 2;
    }
  }
  cout << max + 1 - has << endl;
  return 0;
}
