n = int(input());
q=[int(i) for i in input().split()];
w=[0 for i in range(0,100000)];
for i in range(0,n):w[q[i]-1]+=1;
res=0;
col=-1;
for i in range(99999,-1,-1):
    if(col>=i):break
    res+=w[i]*(i-col);
    col+=w[i];
print(res)


