n = int(input()) A = list(map(int, input().split())) cnt = [0] * (10 ** 5 + 1) for a in A: cnt[a] += 1 tot = 0 flg = False for i in range(10 ** 5): tot += min(cnt[i], 2) if cnt[i] == 0: print(i) break elif cnt[i] == 1: if flg: print(i) break if tot == n: print(i) break else: flg = True elif cnt[i] == 2 and flg and tot == n: print(i) break