from collections import Counter n = int(input()) A = list(map(int, input().split())) counter = Counter(A) more2_num = 0 for i in range(10**5 + 1): if counter[i] > 2: more2_num += counter[i] - 2 for i in range(10**5 + 1): if counter[i] >= 2: continue if counter[i] == 1: if more2_num > 0: more2_num -= 1 continue print(i) break