import sys input = sys.stdin.readline from collections import * N = int(input()) A = list(map(int, input().split())) cnt = Counter(A) need = 0 for i in range(10**5+10): if cnt[i]>=2: need += 2 elif cnt[i]==1: if need+1==N: print(i) break else: print(i+1) break else: print(i) break