#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 105

struct LOC{

	int X,Y;
};

int N;
int A,B,C,D;
LOC loc[NUM];

bool in_area(LOC a){

	return a.X >= A && a.X <= C && a.Y >= B && a.Y <= D;
}

int calc_to_area(LOC a){

	if(a.X < A){ //左

		if(a.Y < B){ //左上

			return abs(A-a.X)+abs(B-a.Y);

		}else if(a.Y > D){ //左下

			return abs(A-a.X)+abs(D-a.Y);

		}else{//左

			return abs(A-a.X);
		}

	}else if(a.X > C){ //右

		if(a.Y < B){ //右上

			return abs(C-a.X)+abs(B-a.Y);

		}else if(a.Y > D){ //右下

			return abs(C-a.X)+abs(D-a.Y);

		}else{//右

			return abs(C-a.X);
		}


	}else{ //真ん中

		if(a.Y < B){ //上

			return abs(B-a.Y);

		}else if(a.Y > D){ //下

			return abs(D-a.Y);

		}else{//中

			return 0;
		}
	}
}


void func(){


	scanf("%d %d %d %d",&A,&B,&C,&D);

	for(int i = 0; i <= N; i++){

		scanf("%d %d",&loc[i].X,&loc[i].Y);
	}

	int ans = 0;

	for(int i = 0; i < N; i++){

	   int from = i;
	   int to = i+1;
	   int cost;

	   if(in_area(loc[from]) == true && in_area(loc[to]) == true){

			cost = 0;

		}else if(in_area(loc[from]) == true && in_area(loc[to]) == false){

			cost = calc_to_area(loc[to]);

		}else if(in_area(loc[from]) == false && in_area(loc[to]) == true){

			cost = calc_to_area(loc[from])-1;

		}else{ //in_area(loc[from]) == false && in_area(loc[to]) == false

			cost = abs(loc[from].X-loc[to].X)+abs(loc[from].Y-loc[to].Y); //直接
			cost = min(cost,calc_to_area(loc[from])+calc_to_area(loc[to])-1); //安全地帯経由
		}

	    ans += cost;
	}

	printf("%d\n",ans);
}

int main(){

	while(true){

		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}


