n = int(input())
a = [int(i) for i in input().split()]
l = 0
dp = [0] * (max(a))
for i in a:
    dp[i-1]+=1
while len(dp)>0:
    d = dp[-1]
    l+=d*len(dp)
    if len(dp)==0 or d>=len(dp):
        break
    dp = dp[d:-1]
            
print(l)