#include <bits/stdc++.h>
double min(double a, double b) { return a < b ? a : b; }
int cross2(int x1, int y1, int x2, int y2) { return x1 * y2 - x2 * y1; }
int cross(int x0, int y0, int x1, int y1, int x2, int y2) {
  return cross2(x1 - x0, y1 - y0, x2 - x0, y2 - y0);
}
int main() {
  static int xx[30], yy[30];
  int n, xs, ys, xe, ye, i, intersect;
  double perim, perim_, x3, y3, x4, y4, ans;
  scanf("%d%d%d%d%d", &xs, &ys, &xe, &ye, &n);
  for (i = 0; i < n; i++) scanf("%d%d", &xx[i], &yy[i]);
  intersect = 0, perim = perim_ = 0;
  for (i = 0; i < n; i++) {
    int x1 = xx[i], y1 = yy[i], x2 = xx[(i + 1) % n], y2 = yy[(i + 1) % n];
    int cse1 = cross(xs, ys, xe, ye, x1, y1),
        cse2 = cross(xs, ys, xe, ye, x2, y2);
    double d = hypot(x2 - x1, y2 - y1), t;
    perim += d;
    if (cse1 > 0 && cse2 > 0)
      perim_ += d;
    else if (cse1 > 0 || cse2 > 0) {
      int c12s = cross(x1, y1, x2, y2, xs, ys),
          c12e = cross(x1, y1, x2, y2, xe, ye);
      if (c12s * c12e >= 0) break;
      intersect = 1;
      t = (double)cross2(xs - x1, ys - y1, xe - xs, ye - ys) /
          cross2(x2 - x1, y2 - y1, xe - xs, ye - ys);
      if (cse1 > 0) {
        x3 = x1 + (x2 - x1) * t, y3 = y1 + (y2 - y1) * t;
        perim_ += t * d;
      } else {
        x4 = x1 + (x2 - x1) * t, y4 = y1 + (y2 - y1) * t;
        perim_ += (1 - t) * d;
      }
    }
  }
  if (!intersect)
    ans = hypot(xe - xs, ye - ys);
  else
    ans = hypot(x3 - xs, y3 - ys) +
          min(hypot(x4 - x3, y4 - y3) * 2, min(perim_, perim - perim_)) +
          hypot(xe - x4, ye - y4);
  printf("%f\n", ans);
  return 0;
}
