#include <bits/stdc++.h>
using namespace std;
long long a[100005];
map<int, int> mp;
int main() {
  int n;
  long long ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int last = -1;
  for (auto it : mp) {
    if ((it.second) / 2 > 0) mp[it.first + 1] += (it.second) / 2;
    mp[it.first] = (it.second) % 2;
    if (mp[it.first] == 1) {
      ans += (long long)(it.first - last - 1);
      last = it.first;
    }
  }
  cout << ans << endl;
  return 0;
}
