object Main{
  def solve(h:Array[Int]) : Int = {
    if(h.length == 1) {
      return 0
    }
    if(h.length == 2) {
      return Math.abs(h(0)-h(1))
    }
    return Math.min(
      solve(h.drop(1)) + Math.abs(h(0)-h(1)),
      solve(h.drop(2)) + Math.abs(h(0)-h(2))
    )
  }

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

