#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int popcount(T t) {
  if (std::numeric_limits<T>::digits <=
      std::numeric_limits<unsigned int>::digits) {
    return __builtin_popcount(t);
  } else {
    return __builtin_popcountll(t);
  }
}
const long double EPS = 1e-8;
const long double PI = acosl(0.0) * 2;
void solve() {
  long long ans = 0;
  int n;
  cin >> n;
  long long last = 0, cnt = 0;
  for (int i = 0; i < int(n); ++i) {
    long long x;
    cin >> x;
    while (last < x && cnt > 0) {
      if (cnt % 2 == 0) ++ans;
      cnt /= 2;
      ++last;
    }
    ans += x - last;
    last = x;
    cnt += 1;
  }
  while (cnt > 0) {
    if (cnt % 2 == 0) ++ans;
    cnt /= 2;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
