In the International City of Pipe Construction, it is planned to repair the water pipe at a certain point in the water pipe network. The network consists of water pipe segments, stop valves and source point. A water pipe is represented by a segment on a 2D-plane and intersected pair of water pipe segments are connected at the intersection point. A stop valve, which prevents from water flowing into the repairing point while repairing, is represented by a point on some water pipe segment. In the network, just one source point exists and water is supplied to the network from this point.

Of course, while repairing, we have to stop water supply in some areas, but, in order to reduce the risk of riots, the length of water pipes stopping water supply must be minimized. What you have to do is to write a program to minimize the length of water pipes needed to stop water supply when the coordinates of end points of water pipe segments, stop valves, source point and repairing point are given.



Input

A data set has the following format:

> N M
>  xs1 ys1 xd1 yd1
>  ...
>  xsN ysN xdN ydN
>  xv1 yv1
>  ...
>  xvM yvM
>  xb yb
>  xc yc
>

The first line of the input contains two integers, N (1 ≤ N ≤ 300) and M (0 ≤ M ≤ 1,000) that indicate the number of water pipe segments and stop valves. The following N lines describe the end points of water pipe segments. The i-th line contains four integers, xsi, ysi, xdi and ydi that indicate the pair of coordinates of end points of i-th water pipe segment. The following M lines describe the points of stop valves. The i-th line contains two integers, xvi and yvi that indicate the coordinate of end points of i-th stop valve. The following line contains two integers, xb and yb that indicate the coordinate of the source point. The last line contains two integers, xc and yc that indicate the coordinate of the repairing point.

You may assume that any absolute values of coordinate integers are less than 1,000 (inclusive.) You may also assume each of the stop valves, the source point and the repairing point is always on one of water pipe segments and that that each pair among the stop valves, the source point and the repairing point are different. And, there is not more than one intersection between each pair of water pipe segments. Finally, the water pipe network is connected, that is, all the water pipes are received water supply initially.

Output

Print the minimal length of water pipes needed to stop water supply in a line. The absolute or relative error should be less than or 10-6. When you cannot stop water supply to the repairing point even though you close all stop valves, print "`-1`" in a line.

Examples

Input

1 2
0 0 10 0
1 0
9 0
0 0
5 0


Output

9.0


Input

5 3
0 4 2 4
0 2 2 2
0 0 2 0
0 0 0 4
2 0 2 4
0 2
1 0
2 2
1 4
2 1


Output

3.0


Input

2 1
0 0 0 4
0 2 2 2
1 2
0 1
0 3


Output

-1

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def dot3(O, A, B):
	(ox, oy) = O
	(ax, ay) = A
	(bx, by) = B
	return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy)

def cross3(O, A, B):
	(ox, oy) = O
	(ax, ay) = A
	(bx, by) = B
	return (ax - ox) * (by - oy) - (bx - ox) * (ay - oy)

def dist2(A, B):
	(ax, ay) = A
	(bx, by) = B
	return (ax - bx) ** 2 + (ay - by) ** 2

def is_intersection(L1, L2):
	P0 = L1[:2]
	P1 = L1[2:]
	Q0 = L2[:2]
	Q1 = L2[2:]
	C0 = cross3(P0, P1, Q0)
	C1 = cross3(P0, P1, Q1)
	D0 = cross3(Q0, Q1, P0)
	D1 = cross3(Q0, Q1, P1)
	if C0 == C1 == 0:
		return False
	return C0 * C1 <= 0 and D0 * D1 <= 0

def cross_point(L1, L2):
	(x0, y0, x1, y1) = L1
	(x2, y2, x3, y3) = L2
	dx0 = x1 - x0
	dy0 = y1 - y0
	dx1 = x3 - x2
	dy1 = y3 - y2
	s = (y0 - y2) * dx1 - (x0 - x2) * dy1
	sm = dx0 * dy1 - dy0 * dx1
	if s < 0:
		s = -s
		sm = -sm
	if s == 0:
		x = x0
		y = y0
	elif s == sm:
		x = x1
		y = y1
	else:
		x = x0 + s * dx0 / sm
		y = y0 + s * dy0 / sm
	return (x, y)

def solve():
	(N, M) = map(int, readline().split())
	ps = set()
	mp = {}
	LS = []
	for i in range(N):
		(x1, y1, x2, y2) = map(int, readline().split())
		mp[x1, y1] = 0
		mp[x2, y2] = 0
		LS.append((x1, y1, x2, y2))
	for i in range(N):
		L1 = LS[i]
		for j in range(i + 1, N):
			L2 = LS[j]
			if is_intersection(L1, L2):
				(x, y) = cross_point(L1, L2)
				mp[x, y] = 0
	for i in range(M):
		(x, y) = map(int, readline().split())
		mp[x, y] = 1
	(xb, yb) = map(int, readline().split())
	mp[xb, yb] = 2
	(xc, yc) = map(int, readline().split())
	mp[xc, yc] = 2
	(*ps1,) = mp.keys()
	ps1.sort(key=lambda x: (x[0], x[1]))
	mv = {e: i for (i, e) in enumerate(ps1)}
	(*ps2,) = mp.keys()
	ps2.sort(key=lambda x: (x[1], x[0]))
	ES = []
	ms = list(map(mv.__getitem__, ps2))
	ks = list(map(mp.__getitem__, ps1))
	K = len(ps1)
	G = [[] for i in range(K)]
	for (x1, y1, x2, y2) in LS:
		vs = []
		if x1 != x2:
			if not x1 <= x2:
				(x1, y1, x2, y2) = (x2, y2, x1, y1)
			for (k, (x, y)) in enumerate(ps1):
				if x1 <= x <= x2 and abs((x - x1) * (y2 - y1) - (y - y1) * (x2 - x1)) < 1e-06:
					vs.append(k)
		else:
			if not y1 <= y2:
				(y1, y2) = (y2, y1)
			for (k, (x, y)) in zip(ms, ps2):
				if y1 <= y <= y2 and abs((x - x1) * (y2 - y1) - (y - y1) * (x2 - x1)) < 1e-06:
					vs.append(k)
		for i in range(len(vs) - 1):
			k1 = vs[i]
			k2 = vs[i + 1]
			G[k1].append(k2)
			G[k2].append(k1)
			ES.append((k1, k2) if k1 <= k2 else (k2, k1))
	s = mv[xc, yc]
	t = mv[xb, yb]
	que = deque([s])
	used = [0] * K
	used[s] = 1
	e_used = set()
	while que:
		v = que.popleft()
		for w in G[v]:
			if w == t:
				write('-1\n')
				return
			e_used.add((v, w) if v <= w else (w, v))
			if not used[w] and ks[w] != 1:
				que.append(w)
			used[w] = 1
	que.append(t)
	e_used1 = set()
	used = [0] * K
	used[t] = 1
	while que:
		v = que.popleft()
		for w in G[v]:
			e = (v, w) if v <= w else (w, v)
			if e in e_used:
				continue
			e_used1.add(e)
			if not used[w]:
				que.append(w)
				used[w] = 1
	ans = 0
	for (k1, k2) in ES:
		if (k1, k2) in e_used1:
			continue
		(x1, y1) = ps1[k1]
		(x2, y2) = ps1[k2]
		ans += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
	write('%.16f\n' % ans)
solve()