#include <bits/stdc++.h>
int a[100010];
void solve(int n) {
  int i, j, cnt, num, len, ans;
  ans = a[0];
  cnt = 0;
  for (i = 0; i < n; i = j) {
    for (j = i + 1; j < n && a[j] == a[i]; j++)
      ;
    len = j - i + cnt;
    cnt = 0;
    num = a[i];
    while (len > 0 && j < n && num < a[j]) {
      if ((len & 1) == 0) {
        ans++;
      }
      num++;
      len >>= 1;
    }
    if (j < n) {
      if (len == 0) {
        ans += (a[j] - num);
      } else {
        cnt = len;
      }
    } else {
      while (len > 0) {
        if ((len & 1) == 0) {
          ans++;
        }
        len >>= 1;
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  int n, i;
  while (scanf("%d", &n) == 1) {
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    solve(n);
  }
  return 0;
}
