Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order. 

Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0). 

Help Ivan, find the required quantity of numbers.

Input

The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an.

Output

Print a single integer — the answer to the problem.

Examples

Input

4
0 1 1 1


Output

0


Input

1
3


Output

3

Note

In the first sample you do not need to add anything, the sum of numbers already equals 23 - 1 = 7.

In the second sample you need to add numbers 20, 21, 22.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;

public class Main {

    public void Run() throws IOException {
        bufferReader = new BufferedReader(new InputStreamReader(System.in));
        writer = new PrintWriter(System.out);
        int n = nextInt();
        int[] exp = new int[n];
        for (int i = 0; i < n; i++) {
            exp[i] = nextInt();
        }
        Arrays.sort(exp);
        int rest = 0, bit = 0, res = 0;
        for (int i = 0; i < n; i++) {
            while (bit < exp[i] && rest != 0) {
                bit++;
                if ((rest & 1) == 0) res++;
                rest /= 2;
            }
            if (bit < exp[i]) {
                res += exp[i] - bit;
                bit = exp[i];
            }
            rest++;
        }
        while (rest != 0) {
            bit++;
            if ((rest & 1) == 0) res++;
            rest /= 2;
        }
        System.out.println(res);
    }

    public static void main(String args[]) throws IOException {
        new Main().Run();
    }

    BufferedReader bufferReader;
    PrintWriter writer;
    StringTokenizer str;

    String next() throws IOException {
        while (str == null || !str.hasMoreTokens()) {
            str = new StringTokenizer(bufferReader.readLine());
        }
        return str.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}
