N=int(input()) A=list(map(int, input().split())) cnt=0 res=0 for i in range(N): A[i]+=cnt cnt=A[i]-1 res+=abs(cnt) print(res)