Problem: We have a flat panel with two holes. Pins are nailed on its surface. From the back of the panel, a string comes out through one of the holes to the surface. The string is then laid on the surface in a form of a polygonal chain, and goes out to the panel's back through the other hole. Initially, the string does not touch any pins.

Figures F-1, F-2, and F-3 show three example layouts of holes, pins and strings. In each layout, white squares and circles denote holes and pins, respectively. A polygonal chain of solid segments denotes the string.

<image>
Figure F-1: An example layout of holes, pins and a string

<image>
Figure F-2: An example layout of holes, pins and a string

<image>
Figure F-3: An example layout of holes, pins and a string

When we tie a pair of equal weight stones to the both ends of the string, the stones slowly straighten the string until there is no loose part. The string eventually forms a different polygonal chain as it is obstructed by some of the pins. (There are also cases when the string is obstructed by no pins, though.)

The string does not hook itself while being straightened. A fully tightened string thus draws a polygonal chain on the surface of the panel, whose vertices are the positions of some pins with the end vertices at the two holes. The layouts in Figures F-1, F-2, and F-3 result in the respective polygonal chains in Figures F-4, F-5, and F-6. Write a program that calculates the length of the tightened polygonal chain.

<image>
Figure F-4: Tightened polygonal chains from the example in Figure F-1.

<image>
Figure F-5: Tightened polygonal chains from the example in Figure F-2.

<image>
Figure F-6: Tightened polygonal chains from the example in Figure F-3.

Note that the strings, pins and holes are thin enough so that you can ignore their diameters.

Input

The input consists of multiple datasets, followed by a line containing two zeros separated by a space. Each dataset gives the initial shape of the string (i.e., the positions of holes and vertices) and the positions of pins in the following format.

> m n
>  x1 y1
>  ...
>  xl yl
>

The first line has two integers m and n (2 ≤ m ≤ 100, 0 ≤ n ≤ 100), representing the number of vertices including two holes that give the initial string shape (m) and the number of pins (n). Each of the following l = m + n lines has two integers xi and yi (0 ≤ xi ≤ 1000, 0 ≤ yi ≤ 1000), representing a position Pi = (xi ,yi ) on the surface of the panel.

* Positions P1, ..., Pm give the initial shape of the string; i.e., the two holes are at P1 and Pm , and the string's shape is a polygonal chain whose vertices are Pi (i = 1, ..., m), in this order.
* Positions Pm+1, ..., Pm+n are the positions of the pins.


Note that no two points are at the same position. No three points are exactly on a straight line.

Output

For each dataset, the length of the part of the tightened string that remains on the surface of the panel should be output in a line. No extra characters should appear in the output.

No lengths in the output should have an error greater than 0.001.

Sample Input


6 16
5 4
11 988
474 975
459 16
985 12
984 982
242 227
140 266
45 410
92 570
237 644
370 567
406 424
336 290
756 220
634 251
511 404
575 554
726 643
868 571
907 403
845 283
10 4
261 196
943 289
859 925
56 822
112 383
514 0
1000 457
514 1000
0 485
233 224
710 242
850 654
485 915
140 663
26 5
0 953
180 0
299 501
37 301
325 124
162 507
84 140
913 409
635 157
645 555
894 229
598 223
783 514
765 137
599 445
695 126
859 462
599 312
838 167
708 563
565 258
945 283
251 454
125 111
28 469
1000 1000
185 319
717 296
9 315
372 249
203 528
15 15
200 247
859 597
340 134
967 247
421 623
1000 427
751 1000
102 737
448 0
978 510
556 907
0 582
627 201
697 963
616 608
345 819
810 809
437 706
702 695
448 474
605 474
329 355
691 350
816 231
313 216
864 360
772 278
756 747
529 639
513 525
0 0


Output for the Sample Input


2257.0518296609
3609.92159564177
2195.83727086364
3619.77160684813






Example

Input

6 16
5 4
11 988
474 975
459 16
985 12
984 982
242 227
140 266
45 410
92 570
237 644
370 567
406 424
336 290
756 220
634 251
511 404
575 554
726 643
868 571
907 403
845 283
10 4
261 196
943 289
859 925
56 822
112 383
514 0
1000 457
514 1000
0 485
233 224
710 242
850 654
485 915
140 663
26 5
0 953
180 0
299 501
37 301
325 124
162 507
84 140
913 409
635 157
645 555
894 229
598 223
783 514
765 137
599 445
695 126
859 462
599 312
838 167
708 563
565 258
945 283
251 454
125 111
28 469
1000 1000
185 319
717 296
9 315
372 249
203 528
15 15
200 247
859 597
340 134
967 247
421 623
1000 427
751 1000
102 737
448 0
978 510
556 907
0 582
627 201
697 963
616 608
345 819
810 809
437 706
702 695
448 474
605 474
329 355
691 350
816 231
313 216
864 360
772 278
756 747
529 639
513 525
0 0


Output

2257.0518296609
3609.92159564177
2195.83727086364
3619.77160684813

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
typedef long double ld; 
const ld eps=1E-15;
const ld pi=acos(-1);
const ld INF=1E15;
const int maxn=1E6+5; 
int q,n,m,top;
ld ans,f[maxn];
bool vis[maxn];
int size,head[maxn];
struct pt
{
	ld x,y;
	pt(ld a=0,ld b=0)
	{
		x=a,y=b;
	}
	void operator=(pt A)
	{
		x=A.x,y=A.y;
	}
	ld operator*(pt A)
	{
		return x*A.y-y*A.x;
	}
	pt operator-(pt A)
	{
		return pt(x-A.x,y-A.y);
	}
}target[maxn],barrier[maxn];
struct inf
{
	int id,x;
	inf(int a=0,int b=0)
	{
		id=a,x=b;
	}
}S[maxn];
struct edge
{
	int to,next;
	ld w;
}E[maxn];
//////////////////////////////////////////////////////////////////
//polygon
//////////////////////////////////////////////////////////////////
bool cmp(pt A,pt B)
{
	return A.x<B.x;
}
pt rotate(pt A,ld ra)
{
	return pt(A.x*cos(ra)-A.y*sin(ra),A.x*sin(ra)+A.y*cos(ra));
}
int face(pt A,pt B,pt C)
{
	ld y=(B.y-A.y)/(B.x-A.x)*(C.x-A.x);
	if(A.y+y>=C.y)
		return 1;
	return -1;
}
bool inside(pt A,pt B,pt C)
{
	return min(A.x,B.x)<=C.x&&C.x<=max(A.x,B.x);
}
ld dis(pt A,pt B)
{
	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
int cross(pt A,pt B)
{
	ld d=A*B;
	if(d>=eps)
		return 1;
	else
		return -1;
}
void push(inf A)
{
	if(A.id==S[top].id&&A.x==S[top].x)
		--top;
	else
		S[++top]=A;
}
//////////////////////////////////////////////////////////////////
//polygon
//////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////
//graph
//////////////////////////////////////////////////////////////////
void add(int u,int v,ld w)
{
	E[++size].to=v;
	E[size].next=head[u];
	E[size].w=w;
	head[u]=size;
}
void clear()
{
	for(int i=0;i<=top+1;++i)
		head[i]=0;
	head[maxn-5]=0;
	size=0;
}
ld spfa()
{
	for(int i=0;i<=top;++i)
		f[i]=INF;
	f[0]=0;
	vis[0]=1;
	queue<int>Q;
	Q.push(0);
	while(!Q.empty())
	{
		int u=Q.front();
		vis[u]=0;
		Q.pop();
		for(int i=head[u];i;i=E[i].next)
		{
			int v=E[i].to;
			ld nw=E[i].w+f[u];
			if(nw<f[v])
			{
				f[v]=nw;
				if(!vis[v])
				{
					vis[v]=1;
					Q.push(v);
				}
			}
		}
	}
	return f[top--];
}
bool check(int l,int r)
{
	for(int i=l+1;i<=r-1;++i)
		if(face(barrier[S[l].id],barrier[S[r].id],barrier[S[i].id])!=S[i].x)
			return false;
	return true;
} 
ld get(int x)
{
	clear();
	barrier[maxn-5]=target[x];
	push(inf(maxn-5,0));
	for(int i=1;i<=top;++i)
		for(int j=i+1;j<=top;++j)
			if(check(i,j))
				add(i,j,dis(barrier[S[i].id],barrier[S[j].id]));
	barrier[0]=target[1];
	for(int i=1;i<=top;++i)
		if(check(0,i))
			add(0,i,dis(barrier[0],barrier[S[i].id]));
	return spfa();
}

//////////////////////////////////////////////////////////////////
//graph
//////////////////////////////////////////////////////////////////

void solve()
{
	top=ans=0;
	cin>>n>>m;
	if(n==0&&m==0)
		exit(0);
	for(int i=1;i<=n;++i)
	{
		cin>>target[i].x>>target[i].y;
		target[i]=rotate(target[i],pi/3);
	}
	for(int i=1;i<=m;++i)
	{
		cin>>barrier[i].x>>barrier[i].y;
		barrier[i]=rotate(barrier[i],pi/3);
	}
	sort(barrier+1,barrier+m+1,cmp);
	pt now=target[1];
	for(int i=2;i<=n;++i)
	{
		if(target[i].x>now.x)
		{
			for(int j=1;j<=m;++j)
				if(inside(now,target[i],barrier[j]))
					push(inf(j,face(now,target[i],barrier[j])));
		}
		else
		{
			for(int j=m;j>=1;--j)
				if(inside(now,target[i],barrier[j]))
					push(inf(j,face(now,target[i],barrier[j])));
		}
		now=target[i];
	}
	cout<<fixed<<setprecision(4)<<get(n)<<endl;
}
int main()
{
	ios::sync_with_stdio(false);
	while(true)
		solve();
	return 0;
}