#include <bits/stdc++.h>
int i, j, n, x, sum = 0, t = 0, total = 0;
int main() {
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &x);
      if (x != t) {
        while (total != 0 && t < x) {
          if (total % 2 != 1) sum++;
          total = total / 2;
          t++;
        }
        sum = sum + x - t;
        t = x;
      }
      total++;
    }
    while (total != 0) {
      if (total % 2 != 1) sum++;
      total = total / 2;
    }
    printf("%d\n", sum);
  }
  return 0;
}
