c = [0] * 100001 n = int(input()) for i in list(map(int, input().split())): c[i] += 1 one, aff = False, False sum, k = 0, 0 while True: aff |= c[k] > 2 sum += c[k] if c[k] == 0: print(k) exit() if c[k] == 1: if one: print(k) exit() one = True if sum == n and not aff: print(k) exit() k += 1