n = int(input())
l = list(map(int,input().split()))
d = dict()
for i in range(len(l)):
    d[l[i]] = l.count(l[i])
a,b = 0,0
for k,i in reversed(list(d.items())):
    b += (k-a)*i if (k-a)*i>0 else 0
    a += i
print(b)