n = int(input())
balllist = [0]
for i in map(int, input().split(" ")):
    try:
        balllist[i - 1] += 1
    except:
        while len(balllist) < i: balllist.append(0)
        balllist[i - 1] += 1

def shiftBalls(idx):
    balllist[idx] -= 1
    for i in range(idx):
        if i != 0:
            balllist[i - 1] = balllist[i]
        balllist[i] = 0
        
index = len(balllist) - 1
price = 0
while index != -1:
    if balllist[index] != 0:
        shiftBalls(index)
        price += index + 1
    else: index -= 1

print(price)

