import sys input=sys.stdin.readline N = int(input()) A = set(list(map(int, input().split()))) sorted(A) B = {i-1 for i in list(A)} sorted(B) l = list(B.difference(A)) print(sum(list(j+1 for j in l)))