from collections import Counter n = int(input()) a = list(map(int, input().split())) m = max(a) b = [0]*100001 for v in a: b[v] += 1 f = g = False for i, v in enumerate(b): if v == 0: if f and not g and i > m: print(i-1); break else: print(i); break if v == 1: if f: print(i); break else: f = True if v > 2: g = True