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