program main
  implicit none

  integer :: n, i
  integer(16) :: inf
  integer(16), allocatable :: h(:), dp(:)

  read(*,*) n
  allocate(h(n))
  allocate(dp(n))
  read(*,*) h

  inf = 1000000000000_16
  do i = 1, n
     dp(i) = inf
  end do

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

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

  write(*,*) dp(n)

end program main
