a = int(input())
sumsd = 0
n = list(map(int, input().split()))
while n != []:
	maxz = max(n)
	n.pop(len(n)-1)
	sumsd += maxz
	if n == []:
		break					
	for x in range(0, len(n)-1):
		if n[x] == 1:
			n.pop(x)
		elif n[x] != maxz:
			n[x] -= 1
print(sumsd-1)
			

				