#include <bits/stdc++.h>
using namespace std;
void add(map<int, bool> &c, int a) {
  if (!c[a]) {
    c[a] = true;
    return;
  }
  c[a] = false;
  add(c, a + 1);
}
void solve(istream &in, ostream &out) {
  int n;
  in >> n;
  map<int, bool> c;
  for (int i = 0; i < n; ++i) {
    int a;
    in >> a;
    add(c, a);
  }
  out << 1 + c.rbegin()->first -
             count_if(c.begin(), c.end(),
                      [](pair<int, bool> p) { return p.second; })
      << endl;
}
int main() {
  solve(cin, cout);
  return 0;
}
