n = int(input()) a = list(map(int, input().split())) count = [0] * (n + 1) for num in a: count[num] += 1 excess = [] for i in range(1, n + 1): if count[i] > 1: excess.extend([i] * (count[i] - 1)) missing = [] for i in range(1, n + 1): if count[i] == 0: missing.append(i) excess.sort() missing.sort() total_cost = 0 for x, y in zip(excess, missing): total_cost += abs(x - y) print(total_cost)