import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._

  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  val heights = readLine.trim.split(' ').map(_.toInt)
  val queue = mutable.PriorityQueue()(Ordering.by[(Int, Int), Int](_._2).reverse).also{q ⇒ q.enqueue((n - 1, 0))}
  val minCost = Array.tabulate(n){_ ⇒ Int.MaxValue}.also{a ⇒ a(n - 1) = 0}
  while (queue.nonEmpty){
    val (top, cost) = queue.dequeue()
    if (minCost(top) == cost){
      for (k ← math.max(0, top - k) until top){
        if (minCost(k) > cost + math.abs(heights(top) - heights(k))) {
          minCost(k) = cost + math.abs(heights(top) - heights(k))
          queue.enqueue((k, minCost(k)))
        }
      }
    }
  }
  println(minCost(0))
  implicit class Extend[T](value: T){
    def also(func: T ⇒ Unit): T = {func(value); value}
    def let[A](func: T ⇒ A): A = func(value)
  }
}