n = int(input()) inf = 10 ** 5 + 1 c = [0] * inf for i in list(map(int, input().split())): c[i] += 1 one, ok1, ok2 = 0, True, 0 for i in range(inf): if c[i] >= 1: ok2 = i k = 0 while 1: ok1 &= c[k] <= 2 if c[k] == 1: one += 1 if c[k] == 0 or one > 1 or one == 1 and ok1 and k >= ok2: print(k) exit() k += 1