import core.stdc.stdio;
import std.typecons;
import std.algorithm;
import std.range;
import std.math;
import std.stdio;

void main(){
	alias Tuple!(int,"x",int,"y") pos;
	alias Tuple!(int,"a",int,"b",int,"c",pos,"s",pos,"t",double,"len") line;
	int n,m;
	scanf("%d%d",&n,&m);
	line[] ls = new line[n];
	foreach(ref l;ls){
		scanf("%d%d%d%d",&l.s.x,&l.s.y,&l.t.x,&l.t.y);
		l.a=l.s.y-l.t.y;
		l.b=l.t.x-l.s.x;
		l.c=l.s.x*l.t.y-l.t.x*l.s.y;
		l.len = sqrt(cast(double)((l.t.x-l.s.x)*(l.t.x-l.s.x)+(l.t.y-l.s.y)*(l.t.y-l.s.y)));
	}
	pos[] vlv = new pos[m];
	foreach(ref v;vlv)
		scanf("%d%d",&v.x,&v.y);
	pos src,rep;
	scanf("%d%d%d%d",&src.x,&src.y,&rep.x,&rep.y);
	alias Tuple!(double,"len",int,"idx") li;
	li[][] q=new li[][n];
	static immutable double eps=1e-9;
	foreach(i,ref l;ls){
		foreach(int j,d;ls)
			if(i!=j){
				int w=l.a*d.b-l.b*d.a;
				if(w){
					double x=cast(double)(l.b*d.c-l.c*d.b)/w;
					double y=cast(double)(l.c*d.a-l.a*d.c)/w;
					double len = sqrt((x-l.s.x)*(x-l.s.x)+(y-l.s.y)*(y-l.s.y));
					if(0<=len&&len<=l.len)
						q[i]~=li(len,j);
				}
			}
		foreach(j,v;vlv)
			if(l.a*v.x+l.b*v.y+l.c==0){
				double len = sqrt(cast(double)((l.s.x-v.x)*(l.s.x-v.x)+(l.s.y-v.y)*(l.s.y-v.y)));
				if(0<=len&&len<=l.len){
					q[i]~=li(len,-1919);
					q[i]~=li(len,1919);
				}
			}
		if(l.a*src.x+l.b*src.y+l.c==0){
			double len = sqrt(cast(double)((l.s.x-src.x)*(l.s.x-src.x)+(l.s.y-src.y)*(l.s.y-src.y)));
			if(0<=len&&len<=l.len)
				q[i]~=li(len,114514);
		}
	}
	bool[][] used =new bool[][n];
	foreach(i,ref u;used)
		u=new bool[q[i].length+1];
	alias Tuple!(int,"i",int,"j") ij;
	ij[] r=new ij[1919893];
	int rc;
	int[][] sc = new int[][](n,n);
	foreach(int i,ref l;ls){
		sort(q[i]);
//		q[i].writeln;
		foreach(int j,v;q[i])
			if(0<=v.idx&&v.idx<n)
				sc[v.idx][i]=j;
		if(l.a*rep.x+l.b*rep.y+l.c==0){
			double len = sqrt(cast(double)((l.s.x-rep.x)*(l.s.x-rep.x)+(l.s.y-rep.y)*(l.s.y-rep.y)));
			if(0<=len&&len<=l.len){
				int j=cast(int)q[i].assumeSorted.lowerBound(li(len,-114514)).length;
				r[rc++]=ij(i,j);
				used[i][j]=1;
			}
		}
	}
	int ri;
	while(ri<rc){
		ij fr = r[ri++];
		with(fr){
			assert(used[i][j]);
			if(j<q[i].length){
				if(q[i][j].idx==114514){
					printf("-1\n");
					return;
				}
				if(0<=q[i][j].idx&&q[i][j].idx<n){
					if(!used[i][j+1]){
						used[i][j+1]=true;
						r[rc++]=ij(i,j+1);
					}
					if(!used[q[i][j].idx][sc[i][q[i][j].idx]]){
						used[q[i][j].idx][sc[i][q[i][j].idx]]=true;
						r[rc++]=ij(q[i][j].idx,sc[i][q[i][j].idx]);
					}
				}
			}
			if(0<j){
				if(q[i][j-1].idx==114514){
					printf("-1\n");
					return;
				}
				if(0<=q[i][j-1].idx&&q[i][j-1].idx<n){
					if(!used[i][j-1]){
						used[i][j-1]=true;
						r[rc++]=ij(i,j-1);
					}
					if(!used[q[i][j-1].idx][sc[i][q[i][j-1].idx]]){
						used[q[i][j-1].idx][sc[i][q[i][j-1].idx]]=true;
						r[rc++]=ij(q[i][j-1].idx,sc[i][q[i][j-1].idx]);
					}
				}
			}
		}
	}
	double ans=0;
	foreach(l;ls)
		ans+=l.len;
	ri=0,rc=0;
//	foreach(u;used)
//		u.writeln;
	foreach(i,vs;q){
		foreach(j;1..q[i].length)
			if(vs[j].len-vs[j-1].len<eps&&used[i][j-1])
				used[i][j]=true;
		foreach_reverse(j;1..q[i].length)
			if(vs[j].len-vs[j-1].len<eps&&used[i][j+1])
				used[i][j]=true;
	}
//	foreach(u;used)
//		u.writeln;
	bool[][] vis =new bool[][n];
	foreach(i,ref v;vis)
		v=new bool[q[i].length+1];
	foreach(int i,vs;q)
		foreach(int j,v;vs)
			if(v.idx==114514){
				r[rc++]=ij(i,j);
				vis[i][j]=true;
			}
	while(ri<rc){
		ij fr = r[ri++];
		with(fr){
			assert(vis[i][j]);
//			writeln(i," ",j);
			if(j==0)
				ans-=q[i][j].len;
			else if(j==q[i].length)
				ans-=ls[i].len-q[i][j-1].len;
			else
				ans-=q[i][j].len-q[i][j-1].len;
			if(j<q[i].length){
				if(0<=q[i][j].idx&&q[i][j].idx<n){
					if(!used[q[i][j].idx][sc[i][q[i][j].idx]]&&!used[q[i][j].idx][sc[i][q[i][j].idx]+1]&&!used[i][j+1]){
						if(!vis[q[i][j].idx][sc[i][q[i][j].idx]]){
							vis[q[i][j].idx][sc[i][q[i][j].idx]]=true;
							r[rc++]=ij(q[i][j].idx,sc[i][q[i][j].idx]);
						}
						if(!vis[q[i][j].idx][sc[i][q[i][j].idx]+1]){
							vis[q[i][j].idx][sc[i][q[i][j].idx]+1]=true;
							r[rc++]=ij(q[i][j].idx,sc[i][q[i][j].idx]+1);
						}
						if(!vis[i][j+1]){
							vis[i][j+1]=true;
							r[rc++]=ij(i,j+1);
						}
					}
				}else if(!used[i][j+1]){
					if(!vis[i][j+1]){
						vis[i][j+1]=true;
						r[rc++]=ij(i,j+1);
					}
				}
			}
			if(0<j){
				if(0<=q[i][j-1].idx&&q[i][j-1].idx<n){
					if(!used[q[i][j-1].idx][sc[i][q[i][j-1].idx]]&&!used[q[i][j-1].idx][sc[i][q[i][j-1].idx]+1]&&!used[i][j-1]){
						if(!vis[q[i][j-1].idx][sc[i][q[i][j-1].idx]]){
							vis[q[i][j-1].idx][sc[i][q[i][j-1].idx]]=true;
							r[rc++]=ij(q[i][j-1].idx,sc[i][q[i][j-1].idx]);
						}
						if(!vis[q[i][j-1].idx][sc[i][q[i][j-1].idx]+1]){
							vis[q[i][j-1].idx][sc[i][q[i][j-1].idx]+1]=true;
							r[rc++]=ij(q[i][j-1].idx,sc[i][q[i][j-1].idx]+1);
						}
						if(!vis[i][j-1]){
							vis[i][j-1]=true;
							r[rc++]=ij(i,j-1);
						}
					}
				}else if(!used[i][j-1]){
					if(!vis[i][j-1]){
						vis[i][j-1]=true;
						r[rc++]=ij(i,j-1);
					}
				}
			}
		}
	}
	printf("%.8lf\n",ans);
}