#include <bits/stdc++.h>
using namespace std;
int cmpf(double a, double b = 0) {
  double d = a - b;
  if (d < 1e-6 && d > -(1e-6)) return 0;
  if (d < 0) return -1;
  return 1;
}
struct point {
  double x, y;
  point(double x = 0, double y = 0) : x(x), y(y) {}
  point operator+(point q) { return point(x + q.x, y + q.y); }
  point operator-(point q) { return point(x - q.x, y - q.y); }
  point operator*(double t) { return point(x * t, y * t); }
  point operator/(double t) { return point(x / t, y / t); }
  double operator*(point q) { return x * q.x + y * q.y; }
  double operator%(point q) { return x * q.y - y * q.x; }
  int cmp(point q) const {
    if (int t = cmpf(x, q.x)) return t;
    return cmpf(y, q.y);
  }
  bool operator==(point q) const { return cmp(q) == 0; }
  bool operator!=(point q) const { return cmp(q) != 0; }
  bool operator<(point q) const { return cmp(q) < 0; }
  friend ostream& operator<<(ostream& o, point p) {
    return o << "(" << p.x << ", " << p.y << ")";
  }
  static point pivot;
};
double dist(point p, point q) {
  return sqrt(pow(p.x - q.x, 2) + pow(p.y - q.y, 2));
}
double cross(point p, point q, point r) { return (p - r) % (q - r); }
int ccw(point p, point q, point r) { return cmpf(cross(p, q, r)); }
point rotate(point p, double theta) {
  double rad = theta * 3.14159265359 / 180;
  return point(p.x * cos(rad) - p.y * sin(rad),
               p.x * sin(rad) + p.y * cos(rad));
}
double angle(point a, point b, point c) {
  point u = b - a, v = c - a;
  return acos((u * v) / sqrt((u * u) * (v * v)));
}
bool between(point p, point q, point r) {
  return ccw(p, q, r) == 0 && cmpf((p - q) * (r - q)) <= 0;
}
bool seg_intersect(point p, point q, point r, point s) {
  point A = q - p, B = s - r, C = r - p, D = s - q;
  int a = cmpf(A % C) + 2 * cmpf(A % D);
  int b = cmpf(B % C) + 2 * cmpf(B % D);
  if (a == 3 || a == -3 || b == 3 || b == -3) return false;
  if (a || b || p == r || p == s || q == r || q == s) return true;
  int t = (p < r) + (p < s) + (q < r) + (q < s);
  return t != 0 && t != 4;
}
point pt_seg_intersect(point p, point q, point r, point s) {
  double c = s % r, u = p % s + r % p, v = q % s + r % q;
  u = fabs(u + c);
  v = fabs(v + c);
  return point((p.x * v + q.x * u) / (u + v), (p.y * v + q.y * u) / (u + v));
}
int in_poly(vector<point>& T, point p) {
  double a = 0;
  int N = T.size();
  for (int i = 0; i < N; i++) {
    if (between(T[i], p, T[(i + 1) % N])) return -1;
    a += angle(p, T[i], T[(i + 1) % N]);
  }
  return !cmpf(a - 2 * 3.14159265359) || !cmpf(a + 2 * 3.14159265359);
}
double area_poly(vector<point>& T) {
  double result = 0.0;
  for (int i = 0; i < T.size() - 1; ++i) result += T[i] % T[i + 1];
  result += T[T.size() - 1] % T[0];
  return fabs(result) / 2.0;
}
double perimeter_poly(vector<point>& T) {
  double result = 0.0;
  for (int i = 0; i < T.size() - 1; ++i) result += dist(T[i], T[i + 1]);
  result += dist(T[T.size() - 1], T[0]);
  return fabs(result);
}
pair<vector<point>, vector<point> > cut_poly(vector<point> T, point a,
                                             point b) {
  pair<vector<point>, vector<point> > P;
  double lf1, lf2;
  T.push_back(T.front());
  lf2 = cross(a, b, T[0]);
  for (int i = 0; i < T.size(); ++i) {
    lf1 = lf2;
    lf2 = 0.0;
    if (i != T.size() - 1) lf2 = cross(a, b, T[i + 1]);
    if (lf1 > 1e-6)
      P.first.push_back(T[i]);
    else if (!cmpf(lf1)) {
      P.first.push_back(T[i]);
      P.second.push_back(T[i]);
    } else
      P.second.push_back(T[i]);
    if (lf1 * lf2 < -1e-6) {
      point tmp = pt_seg_intersect(a, b, T[i], T[i + 1]);
      P.first.push_back(tmp);
      P.second.push_back(tmp);
    }
  }
  if (!P.first.empty())
    if (P.first.back() == P.first.front()) P.first.pop_back();
  if (!P.second.empty())
    if (P.second.back() == P.second.front()) P.second.pop_back();
  return P;
}
int main() {
  point b, e;
  int n;
  vector<point> T(40);
  vector<point> pts;
  scanf("%lf %lf %lf %lf %d", &b.x, &b.y, &e.x, &e.y, &n);
  T.clear();
  T.resize(n);
  for (int i = 0; i < n; ++i) {
    scanf("%lf %lf", &T[i].x, &T[i].y);
  }
  for (int i = 0; i < n - 1; ++i) {
    if (seg_intersect(b, e, T[i], T[i + 1]))
      pts.push_back(pt_seg_intersect(b, e, T[i], T[i + 1]));
  }
  if (seg_intersect(b, e, T[n - 1], T[0]))
    pts.push_back(pt_seg_intersect(b, e, T[n - 1], T[0]));
  for (int i = 0; i < pts.size(); ++i) {
    for (int j = i + 1; j < pts.size(); ++j) {
      if (pts[i] == pts[j]) {
        pts.erase(pts.begin() + j);
        if (pts.size() == 1) pts.erase(pts.begin());
      }
    }
  }
  double r;
  if (pts.size() == 1) {
    if (in_poly(T, b) == 1)
      r = 2 * dist(b, pts[0]) + dist(pts[0], e);
    else
      r = dist(b, pts[0]) + 2 * dist(pts[0], e);
  } else if (pts.size() == 2) {
    double d = dist(pts[0], pts[1]);
    pair<vector<point>, vector<point> > pp = cut_poly(T, b, e);
    r = min(perimeter_poly(pp.first) - d, perimeter_poly(pp.second) - d);
    r = min(r, 2 * d);
    double db1 = dist(b, pts[0]), db2 = dist(b, pts[1]);
    if (cmpf(db1, db2) == -1)
      r += db1 + dist(pts[1], e);
    else
      r += db2 + dist(pts[0], e);
  } else {
    if (in_poly(T, b) == 1)
      r = 2 * dist(b, e);
    else
      r = dist(b, e);
  }
  printf("%.9lf\n", r);
  return 0;
}
