n = int(input());
q=[int(i) for i in input().split()];
q.sort();
res=0;
col=0;
temp=0;
i=n-1;
j=0;
while(i!=-1 and col<q[i]):
    j=i-1
    while(j!=-1 and q[j]==q[i]):j-=1;
    res+=(i-j)*(q[i]-col);
    col+=i-j;
    i=j
print(res)


