def damage x, y#safe -> poison
    d = 0
    d += @a - x if @a > x
    d += x - @c if x > @c
    d += @b - y if @b > y
    d += y - @d if y > @d
    d
end

while true
    n = gets.to_i
    break if n == 0
    @a, @b, @c, @d = gets.chomp.split.map(&:to_i)
    d = 0
    x, y = gets.chomp.split.map(&:to_i)
    n.times{
        d1 = (x.between?(@a, @c) && y.between?(@b, @d)) ? 0 : damage(x, y) - 1
        x2, y2 = gets.chomp.split.map(&:to_i)
        d2 = damage(x2, y2)
        d3 = (x - x2).abs + (y - y2).abs
        d += [d1 + d2, d3].min
#        puts "#{d1} #{d2} #{d3} #{d}"
        x, y = x2, y2
        }
    puts d
end
