n = int(input()) a = list(map(int,input().split())) from collections import Counter c = Counter(a) if c[0] == 0: print(0) else: flg = True now = [] for i in range(n+10): if c[i] >= 2: now.append(2) elif c[i] == 1 and flg: now.append(c[i]) flg = False else: break if sum(now) != n or flg: print(len(now)) else: print(len(now)-1)