#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e5 + 10;
int main() {
  priority_queue<int, vector<int>, greater<int>> pq;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    pq.push(x);
  }
  int tot = 0;
  while (pq.size() > 1) {
    int x = pq.top();
    pq.pop();
    int y = pq.top();
    pq.pop();
    if (x == y) {
      pq.push(x + 1);
    } else {
      pq.push(y);
      tot++;
    }
  }
  cout << pq.top() - tot << endl;
  return 0;
}
