#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <complex>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <functional>
#include <string>
#include <sstream>
// #include <tuple>
// #include <regex>

using namespace std;

typedef long long ll;

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))
stringstream ss;


typedef long double D;
const D EPS = 1e-8,INF = 1e12;
	
template<typename T> int sig(T a,T b=0){return a<b-EPS?-1:a>b+EPS?1:0;}
template<typename T> bool eq(T a,T b){ return sig(abs(a-b))==0;}
template<typename T> D norm(T a){ return a*a;}

typedef complex<D> P;
#define X real()
#define Y imag()

// a×b
D cross(const P& a,const P& b){
	return imag(conj(a)*b);
}
// a・b
D dot(const P& a,const P& b) {
	return real(conj(a)*b);
}

int ccw(const P& a,P b,P c){
	b -= a; c -= a;
	if (cross(b,c) > 0)   return +1;       // counter clockwise
	if (cross(b,c) < 0)   return -1;       // clockwise
	if (dot(b,c) < 0)     return +2;       // c--a--b on line
	if (norm(b) < norm(c)) return -2;       // a--b--c on line
	return 0;// same
}

//浮動小数点modで非負の値のみかえす．
D pfmod(D v,D M=2*M_PI){
	return fmod(fmod(v,M)+M,M);
}

//[0,PI)
D AbsArg(D a){
	 D ret=pfmod(max(a,-a),2);
	 return min(ret,2*M_PI-ret);
}

namespace std{
	bool operator < (const P& a,const P& b){
    		return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  	}
  	bool operator == (const P& a,const P& b){
    		return eq(a,b);
   	}
};

struct L : public vector<P> {
	L(const P &a, const P &b) {
	  	push_back(a); push_back(b);
	 }
};

bool isIntersectSS(const L &s, const L &t) {
	return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
	ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

int n;

P O=P(0,0);
P s,g;
vector<P> useps;
bool Comp(const P& p1,const P&p2){
	if(abs(ccw(O,p1,p2))!=1)return abs(p1)>abs(p2);//sameline
	return ccw(O,p1,p2)==ccw(O,s,g);
}


vector<bool> willpass;

typedef vector<P> Poly,ConvexPoly;
#define prev(as, i) as[(i-1+as.size())%as.size()]
#define curr(as, i)  as[i]
#define next(as, i) as[(i+1)%as.size()]

enum { OUT, ON, IN };
int contains(const Poly& ps, const P& p) {
	bool in = false;
	REP(i,ps.size()){
		P a = curr(ps,i) - p, b = next(ps,i) - p;
		if (a.Y > b.Y) swap(a, b);
		if (a.Y <= 0 && 0 < b.Y)
 		if (cross(a, b) < 0) in = !in;
    		if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  	}
	return in ? IN : OUT;
}

bool passcheck(const P& pos,const P& o,const P&to){
	REP(j,willpass.size())if(willpass[j]){
		if(contains({o,pos,to},useps[j])!=OUT)
			return false;
	}
	return true;
}


D dfs(int i,const P& pos,const P& o,D len){
	// if(i==useps.size())return INF;
	// REP(j,i)cerr <<" ";
	// cerr << i <<" "<<pos <<" "<<o<<" "<<len<<endl;

	if(useps[i]==g){
		if(passcheck(pos,o,useps[i]) && sig(abs(g-o),len)<=0){
			// cerr << abs(g)<<" " << abs(g-pos)<<endl;
			return abs(g-pos);
		}else return INF;
	}

	D d=INF;//search
	if(contains({o,pos,g},useps[i])){	//引っかかる場合
		//迂回なし
		// REP(j,i)cerr <<" ";
		// cerr <<"a"<<endl;
		
		bool ok=true;
		REP(j,willpass.size())if(willpass[j]){
			if(contains({o,pos,useps[i]},useps[j])==IN)ok=false;
		}
		if(ok){
			d=min(d,dfs(i+1,pos,useps[i],len-abs(useps[i]-o)));			
		}

		// REP(j,i)cerr <<" ";
		// cerr <<"b"<<endl;
		//迂回させる
	    if(passcheck(pos,o,useps[i])){
	    	vector<bool> tmp=willpass;
	    	REP(j,willpass.size())willpass[j]=false;
	    	fill(ALL(willpass),false);
	        d=min(d,abs(useps[i]-pos)+dfs(i+1,useps[i],o,len));//迂回して通す
	    	willpass=tmp;
	    }

	 //    REP(j,i)cerr <<" ";
		// cerr <<"c"<<endl;

		//そのうち迂回させて通す
		willpass[i]=true;
		d=min(d,dfs(i+1,pos,o,len));//迂回して通す		
	    willpass[i]=false;
	}else{//引っかからない場合
  //  		REP(j,i)cerr <<" ";
		// cerr <<"d"<<endl;

     	d=min(d,dfs(i+1,pos,o,len));//迂回なし	
	}
   // 	REP(j,i)cerr <<" ";
  	// cerr << d<<endl;

	return d;
}

int main(){
	ss   <<fixed <<setprecision(20);
	cout <<fixed <<setprecision(10);
	cerr <<fixed <<setprecision(20);

	while(true){
		cin >> n;if(n==0)break;
		useps.clear();

		D x,y;
		cin >> x >> y;s=P(x,y);
		cin >> x >> y;g=P(x,y);
		vector<P> ps(n);
		REP(i,n){
			cin >> x >> y;ps[i]=P(x,y);
		}

		// only contained
		REP(i,n){
			if(contains({O,s,g},ps[i])){
				useps.push_back(ps[i]);
			}
		}
		useps.push_back(g);
		sort(ALL(useps),Comp);
		willpass=vector<bool>(useps.size());

		// REP(i,useps.size()){
		// 	cerr << useps[i]<<endl;
		// }

		//始点
		D res=dfs(0,s,O,abs(s));
		if(sig(res,INF)<0) cout << res <<endl;
		else cout << -1 <<endl;
	}

	return 0;
 }

Measured memory_bytes: 1340