import scala.annotation.tailrec
import scala.io.StdIn._



object Main extends App {
  solve()
  @tailrec def solve(): Unit = {
    val n = readInt()
    if (n == 0) return
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
    val square = Square(Point(a, b), Point(c, d))
    var minCount = 0
    val Array(x, y) = readLine.trim.split(' ').map(_.toInt)
    var current = Point(x, y)
    for (i ← 1 to n){
      val Array(x, y) = readLine.trim.split(' ').map(_.toInt)
      val next = Point(x, y)
      minCount += Math.min(current.distanceTo(square) + next.distanceFrom(square), current.distanceTo(next))
      current = next
    }
    println(minCount)
    solve()
  }
  case class Point(x: Int, y: Int) {
    def distanceTo(point: Point): Int = Math.abs(x - point.x) + Math.abs(y - point.y)
    def distanceFrom(square: Square): Int = {
      val xDiff = if ((square.left to square.right).contains(x)) 0 else Math.min(Math.abs(x - square.left), Math.abs(x - square.right))
      val yDiff = if ((square.top to square.bottom).contains(y)) 0 else Math.min(Math.abs(y - square.top), Math.abs(y - square.bottom))
      xDiff + yDiff
    }
    def distanceTo(square: Square): Int = Math.max(distanceFrom(square) - 1, 0)
  }
  case class Square(leftTop: Point, rightBottom: Point) {
    def left: Int = leftTop.x
    def top: Int = leftTop.y
    def right: Int = rightBottom.x
    def bottom: Int = rightBottom.y
  }
}
