object Main extends App {

  import scala.io.StdIn._

  val n = readLine.trim.toInt
  val h = readLine.trim.split(' ').map(_.toInt)
  val memo = Array.tabulate(n){_ ⇒ None: Option[Int]}.also{arr ⇒ arr(n - 1) = Some(0)}
  for (i ← (0 until n by 100).reverse){
    minCost(h, memo, i)
  }
  println(minCost(h, memo, 0))
  def minCost(heights: Array[Int], memo: Array[Option[Int]], current: Int = 0): Int = {
    if (current == heights.length) 0
    else {
      memo(current) match {
        case Some(r) ⇒ r
        case None ⇒
          (current + 1 to current + 2).filter(p ⇒ heights.indices.contains(p)).map(p ⇒ minCost(heights, memo, p) + math.abs(heights(p) - heights(current))).min.also{min ⇒ memo(current) = Some(min)}
      }
    }
  }
  implicit class Extend[T](value: T){
    def also(func: T ⇒ Unit): T = {func(value); value}
    def let[A](func: T ⇒ A): A = func(value)
  }
}