#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <map>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X,b.X) ? a.X<b.X : a.Y+EPS<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}
bool intersectSS(const L& a, const L& b){
    return ( ccw(a[0],a[1],b[0]) *ccw(a[0],a[1],b[1]) <= 0 ) &&
        ( ccw(b[0],b[1],a[0]) *ccw(b[0],b[1],a[1]) <= 0 );
}
bool intersectSP(const L& s, const P &p){
    return abs(cross(s[0]-p, s[1]-p))<EPS  && dot(s[0]-p, s[1]-p)<EPS;
}

bool isParallel(const P &a, const P &b){
    return abs(cross(a,b)) < EPS;
}
bool isParallel(const L &a, const L &b){
    return isParallel(a[1]-a[0], b[1]-b[0]);
}

P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  return m[0] + B/A *(m[1]-m[0]);
}

pair<vector<vector<int> >, VP> arrangement(const vector<L> &l, const VP &p){
    vector<VP> cp(l.size());
    VP plist = p;
    for(int i=0; i<(int)l.size(); i++){
        for(int j=i+1; j<(int)l.size(); j++){
            if(!isParallel(l[i], l[j]) && intersectSS(l[i], l[j])){
                P cpij = crosspointLL(l[i], l[j]);
                cp[i].push_back(cpij);
                cp[j].push_back(cpij);
                plist.push_back(cpij);
            }
        }
        for(int j=0; j<(int)p.size(); j++){
            if(intersectSP(l[i], p[j])){
                cp[i].push_back(p[j]);
            }
        }
        cp[i].push_back(l[i][0]);
        cp[i].push_back(l[i][1]);
        plist.push_back(l[i][0]);
        plist.push_back(l[i][1]);
        sort(cp[i].begin(), cp[i].end());
        cp[i].erase(unique(cp[i].begin(), cp[i].end()), cp[i].end());
    }
    sort(plist.begin(), plist.end());
    plist.erase(unique(plist.begin(), plist.end()), plist.end());

    int n = plist.size();
    map<P, int> conv;
    for(int i=0; i<n; i++){
        conv[plist[i]] = i;
    }
    vector<vector<int> > adj(n);
    for(int i=0; i<(int)cp.size(); i++){
        for(int j=0; j<(int)cp[i].size()-1; j++){
            int jidx = conv[cp[i][j]];
            int jp1idx = conv[cp[i][j+1]];
            adj[jidx].push_back(jp1idx);
            adj[jp1idx].push_back(jidx);
        }
    }
    for(int i=0; i<n; i++){
        sort(adj[i].begin(), adj[i].end());
        adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end());
    }
    return make_pair(adj, plist);
}

void dfs(int pos, int sidx, vector<bool> &used, vector<vector<int> > &adj, VP &plist, VP &v){
    if(used[pos]) return;
    used[pos] = true;
    if(pos == sidx) return;
    auto itr = lower_bound(v.begin(), v.end(), plist[pos]);
    if(itr!=v.end() && *itr==plist[pos]) return;
    for(int next: adj[pos]){
        dfs(next, sidx, used, adj, plist, v);
    }
}

void solve(int pos, vector<bool> &used, vector<vector<int> > &adj, VP &plist, vector<L> &llist){
    if(used[pos]) return;
    used[pos] = true;
    for(int next: adj[pos]){
        solve(next, used, adj, plist, llist);
        P p=plist[pos], q=plist[next];
        if(q < p) swap(p, q);
        llist.push_back(L(p, q));
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<L> ls(n);
    double totallength = 0;
    for(int i=0; i<n; i++){
        double xs,ys,xt,yt;
        cin >> xs >> ys >> xt >> yt;
        ls[i] = L(P(xs, ys), P(xt, yt));
        totallength += abs(ls[i][1] -ls[i][0]);
    }
    VP v(m);
    for(int i=0; i<m; i++){
        double x,y;
        cin >> x >> y;
        v[i] = P(x, y);
    }
    sort(v.begin(), v.end());
    double sx,sy,rx,ry;
    cin >> sx >> sy >> rx >> ry;
    P source(sx, sy), repair(rx, ry);

    VP ps = v;
    ps.push_back(source);
    ps.push_back(repair);
    pair<vector<vector<int> >, VP> ret = arrangement(ls, ps);
    vector<vector<int> > &adj = ret.first;
    VP &plist = ret.second;
    int sidx=-1,ridx=-1;
    for(int i=0; i<(int)plist.size(); i++){
        if(plist[i] == source) sidx = i;
        if(plist[i] == repair) ridx = i;
    }
    vector<bool> used(plist.size(), false);
    dfs(ridx, sidx, used, adj, plist, v);
    if(used[sidx]){
        cout << -1 << endl;
    }else{
        vector<L> llist;
        solve(sidx, used, adj, plist, llist);
        sort(llist.begin(), llist.end());
        llist.erase(unique(llist.begin(), llist.end()), llist.end());
        double ans = totallength;
        for(int i=0; i<(int)llist.size(); i++){
            ans -= abs(llist[i][1] -llist[i][0]);
        }
        cout << fixed << setprecision(10);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 8996