#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<long long> a(n, 0);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    int cnt = 0;
    int carry = 0;
    int maxb = 0;
    int filled = 0;
    int i = 0;
    while (i < n) {
      int j = i;
      while (a[j] == a[i] && j < n) j++;
      cnt = j - i;
      filled += cnt % 2 == 0 ? 0 : 1;
      carry = cnt / 2;
      i = j - carry;
      for (int k = i; k < j; ++k) a[k]++;
    }
    maxb = a[n - 1];
    cout << maxb + 1 - filled << endl;
  }
  return 0;
}
