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

int N,M;

const double INF = 1e100;
const double EPS = 1e-12;
typedef complex<double> P; 
typedef pair<P,P> L; 

namespace std{ 
  bool operator < (const P& a, const P& b){ 
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); 
  } 
} 
double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1; //テ・ツ渉催ヲツ卍づィツィツ暗・ツ崢榲」ツつ?
  if(cross(b,c) < -EPS) return -1; // テヲツ卍づィツィツ暗・ツ崢榲」ツつ?
  if(dot(b,c) < -EPS) return 2; // c -- a -- b テ」ツ?ョテ、ツクツ?ァツ崢エテァツキツ?
  if(norm(b) < norm(c)) return -2; // a -- b -- c テ」ツ?ョテ、ツクツ?ァツ崢エテァツキツ?
  return 0; // a -- c -- b テ」ツ?ョテ、ツクツ?ァツ崢エテァツキツ?
}

bool isIntersect(L s1, L s2){
    if(max(real(s1.first), real(s1.second)) + EPS < min(real(s2.first), real(s2.second)) ||
     max(imag(s1.first), imag(s1.second)) + EPS < min(imag(s2.first), imag(s2.second)) ||
     max(real(s2.first), real(s2.second)) + EPS < min(real(s1.first), real(s1.second)) ||
     max(imag(s2.first), imag(s2.second)) + EPS < min(imag(s1.first), imag(s1.second))) return false;

  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}

bool isIntersectSP(L s, P p){ 
  return abs(s.first-p) + abs(s.second-p) - abs(s.second-s.first) < EPS; 
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

struct edge{
  int to,r;
  double c;
};

map<P,int> mf;
int flag[150000];
vector<vector<edge> > G;
void segmentArrangement(const vector<L> &ss,vector<P> &ps){ 
  for(int i=0;i<ss.size();i++){ 
    ps.push_back(ss[i].first); 
    ps.push_back(ss[i].second); 
    for(int j=i+1;j<ss.size();j++) 
      if(isIntersect(ss[i],ss[j])) 
        ps.push_back(crossPoint(ss[i],ss[j])); 
  } 
  sort(ps.begin(),ps.end()); 
  ps.erase(unique(ps.begin(),ps.end()), ps.end()); 
  G = vector<vector<edge> >(ps.size());
  for(int i=0;i<(int)ps.size();i++){
    flag[i] = mf[ps[i]];
  }
  for(int i=0;i<ss.size();i++){ 
    vector<pair<double,int> > list; 
    for(int j=0;j<ps.size();j++) 
      if(isIntersectSP(ss[i],ps[j]))  
        list.push_back(make_pair(norm(ss[i].first-ps[j]), j)); 
    sort(list.begin(),list.end()); 
    for(int j=0;j<list.size()-1;j++){ 
      int a = list[j].second; 
      int b = list[j+1].second; 
      G[a].push_back( (edge){b,  G[b].size(),abs(ps[a] - ps[b])} ); 
      G[b].push_back( (edge){a,G[a].size()-1,abs(ps[a] - ps[b])} );       
    } 
  } 

} 
 
vector<L> ss;
vector<P> ps;
vector<vector<int> > mem;
double solve(){
  int s,t;
  queue<int> q;
  vector<int> used;
  int sum = 0;
  used = vector<int>(G.size(),0);
  mem = vector<vector<int> >(G.size());
  for(int i=0;i<(int)G.size();i++){
    if(flag[i] == 2 ) s = i;
    if(flag[i] == 3 ) t = i;   
    mem[i] = vector<int>(G[i].size(),0);
    sum += G[i].size();
    /*
    cout << "node " << i << endl;
    for(int j=0;j<(int)G[i].size();j++){
      cout << " = > " << G[i][j].to<< " "<< G[i][j].c << endl;
    }
    */
  }
  // cout << sum << endl;
  q.push( t );
  used[t] = 1;
  double res = 0.0;
  while( !q.empty() ){
    int p = q.front(); q.pop();
    //     cout << p << endl;
    if( flag[p] == 1) continue;
    if( p == s ) return -1.0;
    for(int i=0;i<(int)G[p].size();i++){
      int to = G[p][i].to;
      if( used[to] ) continue;
      used[to] = 1;
      q.push( to );
    }
  }

  q.push( s );
  used[s] = 1;
  while( !q.empty() ){
    int p = q.front(); q.pop();
    for(int i=0;i<(int)G[p].size();i++){
      edge e = G[p][i];
      if(mem[p][i]) continue;
      res -= e.c;
      mem[p][i] = 1;
      mem[e.to][e.r]  = 1;
      if( used[e.to] ) continue;
      used[e.to] = 1;
      q.push( e.to );
    }
  }
  for(int i=0;i<N;i++) res += abs(ss[i].first-ss[i].second);

  return res;
}

int main(){
  cin >> N >> M;
  for(int i=0;i<N;i++){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    ss.push_back( L(P(x1,y1),P(x2,y2)) );
  }
  for(int i=0;i<M;i++){
    P a; cin >> a.real() >> a.imag();
    ps.push_back( a );
    mf[a] = 1;
  }
  P c,d;
  cin >> c.real() >> c.imag();
  cin >> d.real() >> d.imag();
  int s,t;
  mf[c] = 2;
  mf[d] = 3;
  ps.push_back(c);
  ps.push_back(d);
 
  segmentArrangement(ss,ps);

  double res = solve();
  if( res < -EPS ) cout << -1 << endl;
  else printf("%.10lf\n",res);

}

Measured memory_bytes: 4340