mod = 998244353 def main(): import sys from collections import Counter input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) C = Counter(A) flg = 1 ans = 0 for a in range(10 ** 5 + 1): if C[a] == 0: break elif C[a] == 1: if flg and (a + 1) * 2 <= N: flg = 0 ans += 1 else: break else: ans += 1 print(ans) if __name__ == '__main__': main()