n = int(input()) a = list(map(int,input().split())) for i in range(1,n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v print(a) total = sum(a) for i in range(n): if i !=0 and a[i] == a[i-1] +1: total -= a[i] print(total)