#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  set<int> x;
  set<int>::iterator it;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    while (true) {
      it = x.find(temp);
      if (it != x.end()) {
        temp++;
        x.erase(it);
      } else {
        x.insert(temp);
        break;
      }
    }
  }
  int prev = 0;
  int ans = 0;
  for (it = x.begin(); it != x.end(); it++) {
    ans += (*it - prev);
    prev = *it + 1;
  }
  cout << ans << endl;
  return 0;
}
