#include <bits/stdc++.h>
using namespace std;
struct pnt {
  double x, y;
  pnt() {}
  pnt(double x, double y) : x(x), y(y) {}
  bool operator<(const pnt& a) const {
    return x < a.x || (x == a.x && y < a.y);
  }
  pnt operator-(const pnt& a) const { return pnt(x - a.x, y - a.y); }
  pnt operator+(const pnt& a) const { return pnt(x + a.x, y + a.y); }
  pnt operator*(const pnt& a) const { return pnt(x + a.x, y + a.y); }
  double operator^(const pnt& a) const { return x * a.y - y * a.x; }
};
struct ppnt {
  pnt a, d;
  ppnt() {}
  ppnt(pnt a, pnt d) : a(a), d(d) {}
};
struct line {
  int a, b, c;
  line() {}
  line(int a, int b, int c) : a(a), b(b), c(c) {}
};
line m;
pnt p[55], s, f, last;
set<pnt> pts;
int n;
int get_val(line l, pnt p) { return l.a * p.x + l.b * p.y + l.c; }
bool check(line l) {
  set<int> s;
  for (int i = 0; i < n; i++) {
    if (get_val(l, p[i]) < 0)
      s.insert(-1);
    else if (get_val(l, p[i]) > 0)
      s.insert(1);
  }
  return (s.size() <= 1);
}
double dist(pnt a, pnt b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool get_point(ppnt p1, ppnt p2) {
  double cp = p1.d ^ p2.d;
  if (cp != 0) {
    double t1 = ((p2.a - p1.a) ^ p2.d) / cp;
    double t2 = ((p2.a - p1.a) ^ p1.d) / cp;
    if ((0 <= t1 && t1 <= 1.0 && 0 <= t2 && t2 <= 1.0)) {
      last.x = p1.a.x + t1 * p1.d.x;
      last.y = p1.a.y + t1 * p1.d.y;
      pts.insert(last);
      return 1;
    }
  }
  return 0;
}
int main() {
  cin >> s.x >> s.y >> f.x >> f.y >> n;
  if (f < s) swap(s, f);
  m = line(s.y - f.y, f.x - s.x, -(s.x * (s.y - f.y) + s.y * (f.x - s.x)));
  for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;
  p[n] = p[0];
  if (check(m))
    printf("%.6lf", dist(s, f));
  else {
    double len = 0, pr = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      pnt a = p[i], b = p[i + 1];
      pr += dist(p[i], p[i + 1]);
      if (b < a) swap(a, b);
      if (get_point(ppnt(s, f - s), ppnt(a, b - a))) {
        if (pts.size() == cnt && cnt == 1)
          len += dist(p[i], p[i + 1]);
        else {
          cnt++;
          if (cnt == 1)
            len += dist(p[i + 1], last);
          else if (cnt == 2)
            len += dist(p[i], last);
        }
      } else if (cnt == 1)
        len += dist(p[i], p[i + 1]);
    }
    if (pts.size() < 2) return printf("%.6lf", dist(s, f)), 0;
    pnt a = *pts.begin(), b = *(++pts.begin());
    if (dist(s, a) > dist(s, b)) swap(a, b);
    double cross = dist(a, b) * 2.0, pref = dist(s, a), suff = dist(f, b);
    double ans = pref + suff + min(cross, min(len, pr - len));
    printf("%.6lf", ans);
  }
  return 0;
}
