n=int(input()) a=list(map(int,input().split())) a.sort() ans=0 for i in range(1,n-1): if a[i]==a[i-1]+1: pass else : ans+=a[1] ans=ans+a[0]+a[n-1] print(ans)