#include <bits/stdc++.h>
long long mod = 1000000007;
using namespace std;
int n;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
map<int, int> M;
int main() {
  int i, j, fl, test;
  scanf("%d", &n);
  int left = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &j);
    M[j]++;
  }
  int ans = 0;
  int curr = -1;
  for (auto it = M.begin(); it != M.end(); it++) {
    int tmp = it->first;
    int freq = it->second;
    if (freq % 2 == 0) {
      ans++;
    }
    ans = ans + (tmp - curr - 1);
    curr = tmp;
    if (freq != 1)
      M[tmp + 1] =
          M[tmp + 1] + ((freq - 1) % 2 == 0 ? (freq - 1) / 2 : (freq) / 2);
  }
  printf("%d\n", ans);
  return 0;
}
