#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin>>N; vector<ll> DP(10001,1e18); DP[0]=0; for(int i=0;i<N;i++){ ll Y; cin>>Y; ll M=1e18; for(int j=0;j<=10000;j++){ M=min(M,DP[j]); DP[j]=M+abs(j-Y); } } ll an=1e18; for(int i=0;i<10001;i++)an=min(an,DP[i]); cout<<an<<endl; }