N = int(input()) A = [int(x) for x in input().split()] result = 0 clusters = [0] + [i for i in range(1, N) if A[i - 1] + 1 != A[i]] for i in reversed(clusters): if i == 0: target = 1 else: target = A[i - 1] + 1 result += A[i] - target print(result)