N = int(input().rstrip())
line = input().rstrip().split(" ")
aimae = int(line[0]) #比較用Ai-1
counter = 0
 
#counterlistに数字を入れる
for i in range(N - 1):
  ai = int(line[i + 1]) #Ai
  while ai < aimae:
    ai += 1
    counter += 1
  aimae = ai
 
print(counter)