import scala.io.Source

object Main {

  def abs(n1: Int, n2: Int): Int = {
    val diff = n1 - n2
    if (diff < 0) -diff else diff
  }

  def main(args: Array[String]) {
    val nodes = Source.stdin.getLines.toSeq.head.split(" ").map(_.toInt).toSeq
    val (car, cdr) = nodes match {
      case car +: cdr => (car, cdr)
    }
    val edges = nodes.zip(cdr :+ car).map {
      case (n1, n2) => abs(n1, n2)
    }
    println(edges.sorted.dropRight(1).sum)
  }

}