#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010];
int st[100010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int t = 0;
  st[t++] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    st[t] = a[i];
    while (t > 0 && st[t] == st[t - 1]) {
      st[t - 1] = st[t - 1] + 1;
      t--;
    }
    t++;
  }
  cout << st[0] + 1 - t;
  return 0;
}
