#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
map<int, int> m;
int n, x;
int main() {
  int i, j, k;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> x;
    m[x]++;
  }
  int t = 0, last;
  for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
    int x = it->first;
    if (m[x] > 1) {
      m[x + 1] += m[x] / 2;
      m[x] %= 2;
    }
    if (m[x]) ++t;
    last = x;
  }
  cout << last - t + 1;
  return 0;
}
