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 <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <map>
#include <complex>
#include <queue>
#include <sstream>
#include <stack>

using namespace std;
typedef double R;
typedef complex<R> P;
typedef pair<P,P> L;
typedef pair<P,R> C;
typedef vector<P> Poly;
#define x real()
#define y imag()
const R PI = acos(-1);
const R EPS = 1e-9;
inline bool near(const P& p,const P& q){ return abs(p-q)<EPS;}
R dot(const P& p,const P& q){ return p.x*q.x+p.y*q.y;}
R det(const P& p,const P& q){ return p.x*q.y-p.y*q.x;}
enum LPposit{
  P_CD = -2, //counter direction
  P_CW = -1, //clock wise
  P_OS = 0, //on segment
  P_CCW = 1, //counter clock wise
  P_D = 2 //direction
};
inline R ccw_b(const P& p,const P& q,const P& r){  return det(q-p,r-p);}
LPposit ccw(const P& p, const P& q, const P& r){
  R c = ccw_b(p,q,r);
  if(c<-EPS) return P_CW;
  if(c>EPS) return P_CCW;
  if(dot(q-p,r-p)<-EPS) return P_CD;
  if(dot(p-q,r-q)<-EPS) return P_D;
  return P_OS;
}
inline R Sabs(const L& l){ return abs(l.first-l.second);}
inline R LPdist(const L& l,const P& p){ return abs(ccw_b(l.first,l.second,p))/Sabs(l);}
inline R SPdist(L l,P p){
  R a = abs(l.first-p);
  R b = abs(l.second-p);
  R c = Sabs(l);
  if(b*b+c*c>a*a && a*a+c*c>b*b) return LPdist(l,p);
  return min(a,b);
}
bool crossS(const L& p,const L& q){
  return
    ccw(p.first,p.second,q.first)*ccw(p.first,p.second,q.second)<=0 &&
    ccw(q.first,q.second,p.first)*ccw(q.first,q.second,p.second)<=0;
}
P intersect(const L& p,const L& q){
  P vp = p.second-p.first;
  P vq = q.second-q.first;
  P c(det(vp,p.first), det(vq,q.first));
  return P(det(c, P(vp.x, vq.x)), det(c, P(vp.y, vq.y))) / det(vp, vq);
}

int inConvex(const Poly& ps, P p){
  int n = ps.size();
  int c = ccw(ps[n-1],p,ps[0]);
  for(int i=0;i+1<n;++i)
    if(ccw(ps[i],p,ps[i+1])!=c) return false;
  return true;
}

vector<P> incP(const vector<P>& v,const Poly& pol){ //pol?????????????????????v???????´??????????
  int n = v.size();
  vector<P> ret;
  for(int i=0;i<n;++i) if(inConvex(pol,v[i])==1) ret.push_back(v[i]);
  return ret;
}

vector<P> himo;
vector<P> kugi;

double input(){
  double ret;
  cin >> ret;
  return ret;
}

R angle(const P& a,const P& b){
  int sgn = (det(a,b)>=0)?1:-1;
  return acos(dot(a,b)/abs(a)/abs(b))*sgn;
}

struct D{
  P p,pre;
  R deg; //????????????????§????
  D(P a,P b,R d):p(a),pre(b),deg(d){}
};

P nextKugi(const Poly& pol,vector<P> tmp){
  P s = pol[0];
  P v1=pol[1]-s, v2=pol[2]-s;
  double argmin = abs(angle(v1,v2));
  vector<P> ps = incP(tmp,pol);
  int n = ps.size();
  P nxt = 0;
  bool found = false;
  for(int i=0;i<n;++i){
    double ag = abs(angle(v1,ps[i]-s));
    if(ag < argmin){
      found = true;
      argmin = ag;
      nxt = ps[i];
    }
  }
  if(!found) return P(-1,-1);
  return nxt;
}

vector<P> path(vector<P> ps,const Poly& pol){ //pol???????§???¢, v???pol??????????????????
  P s = pol[0];
  vector<P> ret;
  while(true){
    int n = ps.size();
    P v1 = pol[1]-s, v2=pol[2]-s;
    double argmin = abs(angle(v1,v2));
    P nxt = 0;
    bool found = false;
    for(int i=0;i<n;++i){
      if(ps[i]==s) continue;
      double ag = abs(angle(v1,ps[i]-s));
      if(ag < argmin){
	found = true;
	argmin = ag;
	nxt = ps[i];
      }
    }
    if(!found) break;
    ret.push_back(nxt);
    vector<P> tmp;
    Poly POL = pol; POL[0]=nxt;
    for(int i=0;i<n;++i)
      if(inConvex(POL,ps[i])) tmp.push_back(ps[i]);
    ps = tmp;
    s = nxt;
  }
  return ret;
}


R solve(){
  if(himo.size()==2) return abs((himo[1]-himo[0]));
  P A = himo[0];
  P B = himo[1];
  stack<D> St;
  int n = himo.size();
  for(int i=2;i<n;++i){
    P C = himo[i];
    while(!St.empty()){
      Poly ABC(3);
      ABC[0]=A, ABC[1]=B, ABC[2]=C;
      P K = nextKugi(ABC,kugi);
      if(K==P(-1,-1)) K = C;
      D X = St.top(); St.pop();
      double nxtdeg = X.deg+angle(B-A,K-A);
      if(X.deg * nxtdeg < 0){
	B = intersect(L(X.pre,X.p), L(B,C));
	A = X.pre;
      }
      else{
	X.deg = nxtdeg;
	St.push(X);
	break;
      }
    }

    Poly ABC(3); ABC[0]=A, ABC[1]=B, ABC[2]=C;
    vector<P> ins = incP(kugi,ABC);
    vector<P> ps = path(ins,ABC);
    ps.push_back(C);
    for(int j=0;j+1<ps.size();++j){
      St.push(D(ps[j], A, angle(ps[j]-A, ps[j+1]-ps[j])));
      A = ps[j];
    }
    B = C;
  }

  vector<P> X;
  X.push_back(himo[n-1]);
  while(!St.empty()){
    X.push_back(St.top().p);
    St.pop();
  }
  X.push_back(himo[0]);
  reverse(X.begin(), X.end());
  
  ofstream ofs("1164.dat");
  for(int i=0;i<X.size();++i) ofs << X[i].x << " " << X[i].y << endl;

  R ret = 0;
  for(int i=0;i+1<X.size();++i) ret+=abs(X[i+1]-X[i]);
  return ret;
}

int main(){
  int n,m;
  while(cin>>m>>n,m||n){
    himo.clear();
    kugi.clear();
    ofstream ofsh("himo.dat");
    ofstream ofsk("kugi.dat");
    for(int i=0;i<m;++i)
      himo.push_back(P(input(),input()));
    for(int i=0;i<n;++i)
      kugi.push_back(P(input(),input()));

    for(int i=0;i<m;++i)
      ofsh<<himo[i].x << " " << himo[i].y << endl;
    for(int i=0;i<n;++i)
      ofsk<<kugi[i].x << " " << kugi[i].y << endl;
    
    cout << fixed << setprecision(10) << solve() << endl;
  }
  return 0;
}