N = int(input()) A = list(map(int, input().split())) A.sort() indl = 0 indr = N res = 0 M = 10**5 ct1 = 0 for i in range(M): ct = 0 while indl < indr and A[indl] == i: ct += 1 indl += 1 if ct == 0: print(i) exit() if ct == 1: ct1 += 1 if ct1 == 2: print(i) exit() if res: res -= 1 elif indl == indr: print(i) exit() else: indr -= 1 indr -= 1 else: res += ct-2