#include <bits/stdc++.h>

const int N = 250;
const double eps = 1e-9;
const double INF = 1e200;

int n, m;
struct Point {
	double x, y;
	
	Point() {}
	Point(double x, double y):x(x), y(y) {}
	
	void print() {
		printf("(%.2f, %.2f)\n", x, y);
	}
	
	friend Point operator + (const Point &a, const Point &b) {
		return Point(a.x + b.x, a.y + b.y);
	}
	
	friend Point operator - (const Point &a, const Point &b) {
		return Point(a.x - b.x, a.y - b.y);
	}
	
	friend Point operator * (const Point &a, const double &b) {
		return Point(a.x * b, a.y * b);
	}
};
Point string[N], pin[N];

int dcmp(double x) {
	if (std::abs(x) < eps) {
		return 0;
	}
	return x < 0 ? -1 : 1;
}

double cross(Point a, Point b) {
	return a.x * b.y - a.y * b.x;
}

double dot(Point a, Point b) {
	return a.x * b.x + a.y * b.y;
}

double getAngle(Point o, Point a, Point b) {
	return std::atan2(cross(a - o, b - o), dot(a - o, b - o));
}

double area(Point a, Point b, Point c) {
	return std::abs(cross(b - a, c - a)) / 2.0;
}

double sqr(double x) {
	return x * x;
}

double dist(Point a, Point b) {
	return std::sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}

bool inTriangle(Point p, Point a, Point b, Point c) {
	return dcmp(area(p, a, b) + area(p, b, c) + area(p, c, a) - area(a, b, c)) == 0
	&& dcmp(area(p, a, b)) == dcmp(area(p, b, c)) && dcmp(area(p, a, b)) == dcmp(area(p, a, c))
	;
}

Point getIntersection(Point p, Point v, Point q, Point w) {
	v = v - p;
	w = w - q;
	Point u = p - q;
	double t = cross(w, u) / cross(v, w);
	return p + (v * t);
}

void init() {
	for (int i = 1; i <= n; i ++) {
		double x, y;
		scanf("%lf%lf", &x, &y);
		string[i] = Point(x, y);
	}
	for (int i = 1; i <= m; i ++) {
		double x, y;
		scanf("%lf%lf", &x, &y);
		pin[i] = Point(x, y);
	}
}

void work() {
	std::vector<Point> answer;
	std::vector<double> exAngle;
	Point last, mid;
	
	answer.push_back(string[1]);
	last = string[1], mid = string[2];
	exAngle.push_back(INF);
	for (int i = 3; i <= n; i ++) {
		while (true) {
			double minAngle = getAngle(last, string[i], mid);
			Point tmp = string[i];
			bool tag = false;
			for (int j = 1; j <= m; j ++) {
				if (inTriangle(pin[j], last, mid, string[i])) {
					if (std::abs(getAngle(last, pin[j], mid)) < std::abs(minAngle)) {
						tag = true;
						minAngle = getAngle(last, pin[j], mid);
						tmp = pin[j];
					}
				}
			}
			if (dcmp(exAngle.back()) * dcmp(exAngle.back() + minAngle) == -1) {
				answer.pop_back();
				exAngle.pop_back();
				mid = getIntersection(answer.back(), last, mid, string[i]);
				last = answer.back();
			} else {
				exAngle.back() += minAngle;
				if (tag == false) {
					mid = string[i];
					break;
				}
				mid = getIntersection(last, tmp, mid, string[i]);
				answer.push_back(tmp);
				exAngle.push_back(0);
				last = tmp;
			}
		}
		/*
		printf("i = %d:\n", i);
		for (int j = 0; j < (int)answer.size(); j ++) {
			answer[j].print();
		}
		*/
	}
	answer.push_back(string[n]);
	
	double length = 0;
	for (int i = 1; i < (int)answer.size(); i ++) {
		length += dist(answer[i - 1], answer[i]);
	}
	printf("%.10f\n", length);
}

int main() {
	//freopen("input.txt", "r", stdin);
	
	while (std::cin >> n >> m && !(n == 0 && m == 0)) {
		init();
		work();
	}
	
	return 0;
}

Measured memory_bytes: 1396