n = int(input()) y = list(map(int,input().split())) dp = [[0] * (10**4+1) for _ in range(1+n)] # dp[0][0] = 0 for i in range(1,n+1): for j in range(10**4+1): if(j==0): dp[i][j] = dp[i-1][j] + abs(j-y[i-1]) else: dp[i][j] = min(dp[i][j-1], dp[i-1][j] + abs(j-y[i-1])) print(min(dp[i]))