from copy import copy F=10**10 N=int(input()) Y=list(map(int,input().split())) D=[[F]*(10**4+1) for _ in range(N+1)] D[0][1]=0 for i in range(N): y=Y[i] m=F for j in range(10**4+1): m=min(m,D[i][j]) D[i+1][j]=min(D[i+1][j],m+abs(y-j)) print(min(D[-1]))