N = int(input()) Y = list(map(int,input().split())) my = max(Y)+1 DP = [0]*(my) for y in Y: NDP1 = [0]*my for i in range(my): NDP1[i] = DP[i]+abs(y-i) NDP = [10**7]*my for i in range(my): NDP[i] = min(NDP[i-1],NDP1[i]) DP = NDP print(min(DP))