#include <bits/stdc++.h>
using namespace std;
int a[100002];
int main() {
  int n, i;
  int in;
  int sum;
  int innum;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  in = a[0];
  innum = 1;
  sum = 0;
  for (i = 1; i < n; i++) {
    if (a[i] == in)
      innum++;
    else {
      while (1) {
        if (innum % 2 == 1) sum++;
        innum /= 2;
        in++;
        if (innum == 0) {
          in = a[i];
          innum = 1;
          break;
        } else if (a[i] == in) {
          innum++;
          break;
        }
      }
    }
  }
  while (1) {
    if (innum % 2 == 1) sum++;
    innum /= 2;
    in++;
    if (innum == 0) {
      innum = 1;
      break;
    }
  }
  printf("%d\n", in - sum);
  return 0;
}
