n=int(input())
a=list(map(int,input().split()))
dic={i:0 for i in list(set(a))}
for i in a:
    dic[i]+=1
keys=list(dic.keys())
keys.reverse()
zdvig=0
res=0
for k in keys:
    if k<=zdvig:
        break
    res+=(k-zdvig)*dic[k]
    zdvig+=dic[k]
print(res)
