import bisect n = int(input()) a = list(map(int, input().split())) a.sort() m = 0 while True: i = bisect.bisect_left(a, m) count_ge = n - i if count_ge < 2: print(m) break m += 1