N = int(input()) A = list(map(int,input().split())) ans = 0 now = A.pop() A = [0] + A while A: b = A.pop() ans += now - b - 1 now = b print(ans)