from collections import deque
n = int(input())
l=[]
rez=0
buf=0
a=list(map(int, input().split()))
size = a[n-1]
for i in range(size):
    l.append(0)
for i in a:
    l[i-1]+=1
l=l[::-1]
d=deque(l, len(l))
for i in range(size):
    if d[i]!=0:
        buf=d[i]
        rez+=d[i]*(size-i)
        d[i]=0
        for j in range(buf):
            d.appendleft(0)
print(rez)



                           
                                                 

