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 <cstdio>
#include <vector>
#include <complex>
#include <cmath>
#include <cfloat>
using namespace std;

#define EPS 1e-9

typedef complex<double> P;
typedef const P &rP;
typedef vector<P> vP;

double pi;
vP ps, pn;

double dot(rP va, rP vb){
	return real(va) * real(vb) + imag(va) * imag(vb);
}

double cross(rP va, rP vb){
	return real(va) * imag(vb) - imag(va) * real(vb);
}

double distance_ls_p(rP a, rP b, rP c){
	if( dot(b - a, c - a) <= 0.0 ) return abs(c - a);
	if( dot(a - b, c - b) <= 0.0 ) return abs(c - b);
	return abs(cross(b - a, c - a)) / abs(b - a);
}

double difangle(double a, double b){
	a += 4.0 * pi;
	while(b < a - pi) b += 2.0 * pi;
	return b - a;
}

bool contains(const vP &plg, rP pt){
	int cnt = 0;
	double y = imag(pt);

	int i = plg.size() - 1;
	for(int j = 0; j < plg.size(); ++j){
		if( distance_ls_p(plg[i], plg[j], pt) < EPS ){
			return false;
		}
		double dyi = imag(plg[i]) - y;
		double dyj = y - imag(plg[j]);
		double tx = (dyi * real(plg[j]) + dyj * real(plg[i])) / (dyi + dyj);

		if(imag(plg[i]) >= y && imag(plg[j]) < y){
			if( tx < real(pt) ) ++cnt;
		}
		else if(imag(plg[i]) < y && imag(plg[j]) >= y){
			if( tx < real(pt) ) ++cnt;
		}

		i = j;
	}

	return (cnt % 2 != 0);
}

P intersect(rP pa1, rP pa2, rP pb1, rP pb2){
	P da12 = pa2 - pa1;
	P db21 = pb1 - pb2;
	P dab1 = pb1 - pa1;

	double t = cross(dab1, db21) / cross(da12, db21);
	return pa1 + t * da12;
}

struct info{
	P pos;
	double to, dif;

	info(rP p, double t, double d): pos(p), to(t), dif(d) {}
};


double solve(){
	vector<info> pnts;
	pnts.reserve(11000);
	pnts.push_back(info(ps[0], arg(ps[1] - ps[0]), DBL_MAX));

	for(int i = 2; i < ps.size(); ++i){
		bool appended = false;
		P prev = ps[i - 1];

		while(1){
			int nidx = -1;
			rP base = pnts.back().pos;
			double baseangle = arg(prev - pnts.back().pos);

			double rot = DBL_MAX;
			if(!appended){
				double c = cross(prev - base, ps[i] - base);
				double r = pi - abs(pnts.back().dif);
				if(pnts.back().dif * c < 0.0){
					if(pnts.back().dif < 0.0){ rot = -r; }
					else{ rot = r; }
				}
			}
			
			vector<P> triangle(3);
			triangle[0] = base;
			triangle[1] = prev;
			triangle[2] = ps[i];
			
			for(int j = 0; j < pn.size(); ++j){
				double r = difangle(baseangle, arg(pn[j] - base));
				if(abs(r) < abs(rot) && contains(triangle, pn[j])){
					rot = r;
					nidx = j;
				}
			}

			if(nidx != -1){
				pnts.back().dif += rot;
				double to = pnts.back().to + rot;
				prev = intersect(prev, ps[i], base, base + polar(1.0, to));
				pnts.back().to = arg(prev - base);

				double next = (rot < 0.0 ? -pi : pi);
				pnts.push_back(info(pn[nidx], to, next));
				appended = true;
			}
			else{
				double ds = difangle(baseangle, arg(ps[i] - base));
				if(abs(rot) < abs(ds)){
					pnts.pop_back();
					double to = pnts.back().to;
					prev = intersect(prev, ps[i], base, base + polar(1.0, to));
				}
				else{
					pnts.back().dif += ds;
					pnts.back().to = arg(ps[i] - base);
					break;
				}
			}
		}
	}

	pnts.push_back(info(ps.back(), 0.0, 0.0));

	double ans = 0.0;
	for(int i = 1; i < pnts.size(); ++i){
		ans += abs(pnts[i].pos - pnts[i-1].pos);
	}

	return ans;
}


int main(){
	pi = acos(-1.0);

	int m, n, x, y;
	while(scanf("%d%d", &m, &n), m){
		ps.resize(m);
		pn.resize(n);

		for(int i = 0; i < m; ++i){
			scanf("%d%d", &x, &y);
			ps[i] = P(x, y);
		}
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &x, &y);
			pn[i] = P(x, y);
		}

		printf("%f\n", solve());
	}
}