#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
long long a[maxn], b[maxn];
int n, top;
long long x;
int main() {
  cin >> n;
  top = 0;
  cin >> a[top];
  b[top] = 1;
  for (int i = 1; i < n; i++) {
    cin >> x;
    if (x != a[top]) {
      a[++top] = x;
      b[top] = 1;
    } else {
      b[top]++;
    }
  }
  long long num = 0;
  for (int i = 0; i < top; i++) {
    long long x = b[i];
    long long y = a[i + 1] - a[i];
    while (x) {
      if (x & 1) num++;
      x >>= 1;
      y--;
      if (!y) {
        b[i + 1] += x;
        break;
      }
    }
  }
  long long ans = a[top];
  if (b[top] & 1) num++;
  b[top] >>= 1;
  while (b[top]) {
    ans++;
    if (b[top] & 1) num++;
    b[top] >>= 1;
  }
  cout << ans - num + 1 << endl;
}
