if __name__ == "__main__": n = int(input()) num_list = list(map(int, input().split(" "))) num_cnt_list = [0] * n for i in range(n): num_cnt_list[num_list[i] - 1] += 1 j = 0 ans = 0 while j < n: if 1 < num_cnt_list[j]: zero_pos = num_cnt_list.index(0) num_cnt_list[j] -= 1 num_cnt_list[zero_pos] += 1 ans += abs(zero_pos - j) j = 0 else: j += 1 print(ans)