#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define bcnt __builtin_popcountll

typedef long double D;
typedef complex<D> P;

#define X real()
#define Y imag()

const D eps=1e-12;
const D inf=1e12;
const D PI=acos(-1);

bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
bool cmp_y(const P& a,const P& b){ return a.Y==b.Y?a.X<b.X:a.Y<b.Y; }
bool cmp_a(const P& a,const P& b){ return arg(a)==arg(b)?norm(a)<norm(b):arg(a)<arg(b); }
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
D toRag(D deg){ return deg*PI/180.0; }
P rot(P base,P a,D theta){ return base+polar(abs(a-base),arg(a-base)+theta); }
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};
P crosspoint(L l,L m) {
  D A=cross(l[1]-l[0],m[1]-m[0]);
  D B=cross(l[1]-l[0],l[1]-m[0]);
  if (abs(A)<eps&&abs(B)<eps) return m[0]; // same line
  if (abs(A)<eps) return P(-100000,-100000);
  return m[0]+B/A*(m[1]-m[0]);
}
bool intersectSP(L s,P p){
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0])<eps;
}

int N,M;
P sp,tp;
vector<L> ls;
vector<P> ps;
struct edge{
  int u,v;
  D cost;
};
vector<int> g[100010];
vector<edge> es;
bool vis[2][100010];

bool exist(P p){
  rep(i,ps.size())if(abs(p-ps[i])<eps)return true;
  return false;
}

int main(){
  cin>>N>>M;
  rep(i,N){
    int x0,y0,x1,y1;
    cin>>x0>>y0>>x1>>y1;
    ls.push_back(L(P(x0,y0),P(x1,y1)));
  }
  rep(i,M){
    int x,y;
    cin>>x>>y;
    ps.push_back(P(x,y));
  }
  {
    int x,y;
    cin>>x>>y;
    sp=P(x,y);
    cin>>x>>y;
    tp=P(x,y);
  }

  ps.push_back(sp); ps.push_back(tp);

  rep(i,N){
    if(!exist(ls[i][0]))ps.push_back(ls[i][0]);
    if(!exist(ls[i][1]))ps.push_back(ls[i][1]);
    rep(j,i){
      P cp=crosspoint(ls[i],ls[j]);
      if(cp==P(-100000,-100000))continue;
      D x0=max(min(ls[i][0].X,ls[i][1].X),min(ls[j][0].X,ls[j][1].X));
      D x1=min(max(ls[i][0].X,ls[i][1].X),max(ls[j][0].X,ls[j][1].X));
      D y0=max(min(ls[i][0].Y,ls[i][1].Y),min(ls[j][0].Y,ls[j][1].Y));
      D y1=min(max(ls[i][0].Y,ls[i][1].Y),max(ls[j][0].Y,ls[j][1].Y));
      if(cp.X<x0||cp.X>x1||cp.Y<y0||cp.Y>y1)continue;
      if(!exist(cp))ps.push_back(cp);
    }
  }

  D sum=0;
  rep(i,N){
    vector<int> idxs;
    rep(j,ps.size()){
      if(intersectSP(ls[i],ps[j]))idxs.push_back(j);
    }
    sort(all(idxs),[=](const int& a,const int& b){ return cmp_x(ps[a],ps[b]); });
    rep(j,idxs.size()-1){
      es.push_back((edge){idxs[j],idxs[j+1],abs(ps[idxs[j]]-ps[idxs[j+1]])});
      sum+=abs(ps[idxs[j]]-ps[idxs[j+1]]);
      g[idxs[j]].push_back(idxs[j+1]);
      g[idxs[j+1]].push_back(idxs[j]);
    }
  }

  {
    queue<int> que;
    que.push(M+1); vis[0][M+1]=true;
    while(que.size()){
      int v=que.front(); que.pop();
      if(v<M)continue;
      for(int nv : g[v]){
        if(vis[0][nv])continue;
        vis[0][nv]=true;
        que.push(nv);
      }
    }
  }
  if(vis[0][M]){
    printf("-1\n");
    return 0;
  }

  {
    queue<int> que;
    que.push(M); vis[1][M]=true;
    while(que.size()){
      int v=que.front(); que.pop();
      if(v<M&&vis[0][v])continue;
      for(int nv : g[v]){
        if(vis[1][nv])continue;
        vis[1][nv]=true;
        que.push(nv);
      }
    }
  }

  D res=sum;
  rep(i,es.size()){
    if(vis[1][es[i].u]&&vis[1][es[i].v]){
      res-=es[i].cost;
    }
  }
  printf("%.10Lf\n", res);

  return 0;
}

