PROGRAM ATCODER

implicit none
integer :: n, i
integer, allocatable :: h(:), dp(:)

read(*,*) n
allocate(h(n), dp(n))
read(*,*) (h(i), i=1,n)

dp = 100000
dp(1) = 0
dp(2) = dp(1) + abs(h(1)-h(2))

do i = 3, n
	call chmin(dp(i), dp(i-1)+abs(h(i)-h(i-1)))
    call chmin(dp(i), dp(i-2)+abs(h(i)-h(i-2)))
end do

write(*,'(i0)') dp(n)

END PROGRAM ATCODER

subroutine chmin(dp,x)
implicit none
integer :: dp, x

if (dp > x) then
	dp = x
	return
end if

return

end subroutine