#include <bits/stdc++.h>
using namespace std;
int n, temp, ans;
vector<int> a;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a.push_back(temp);
    if (a[a.size() - 2] == a[a.size() - 1]) {
      a[a.size() - 2]++;
      a.pop_back();
    }
  }
  bool edit = true;
  while (edit) {
    edit = false;
    for (int i = 0; i < a.size() - 1; i++) {
      if (a[i] == a[i + 1]) {
        a[i]++;
        a.erase(a.begin() + i + 1);
        edit = true;
      }
    }
    sort(a.begin(), a.end());
  }
  for (int i = 0; i < a.size() - 1; i++) {
    if (a[i] + 1 != a[i + 1]) {
      ans += a[i + 1] - a[i] - 1;
    }
  }
  ans += a[0];
  cout << ans;
  return 0;
}
