#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, dem, prev, ans, n, j, u;
  scanf("%d\n", &n);
  dem = 0;
  prev = 0;
  ans = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &u);
    if ((i == 1) || (u == prev))
      dem++;
    else {
      for (j = prev; j <= u - 1; j++) {
        if ((dem % 2) == 1) ans++;
        dem /= 2;
        if (dem == 0) break;
      }
      dem += 1;
    }
    prev = u;
  }
  while (dem != 0) {
    if ((dem % 2) == 1) ans++;
    dem /= 2;
    if (dem != 0) prev++;
  }
  cout << (prev + 1 - ans);
}
