object Main{
  def solve(n:Int,h:Array[Int]) : Int = {
    val memo = scala.collection.mutable.Map.empty[Array[Int], Int]
    if(memo.contains(h)) {
      return memo.getOrElse(h,0)
    }
    val result = n match {
      case 1 => 0
      case 2 => Math.abs(h(0) - h(1))
      case n => Math.min(
        solve(n-1,h.drop(1)) + Math.abs(h(0)-h(1)),
        solve(n-2,h.drop(2)) + Math.abs(h(0)-h(2))
      )
    }
    memo(h) = result
    return result
  }

  def main(args: Array[String]) : Unit = {
    System.err.println("ok")
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val h : Array[Int] = (1 to n).toArray.map{_ => sc.nextInt }
    (n to 1).foreach { x => solve(n-x,h.drop(x))}
    println(solve(n,h))
  }
}

